I have a weird bug in controller with Symfony4Can an ASP.NET MVC controller return an Image?FOSRest Symfony POST using jsonSymfony2 - Dynamic generated form not working while editing formSymfony4 extends controller with route annotationSymfony4 API Controller ParentSymfony4: inject service into controller __construct (constructor)migrating sql query controller symfony4How to display the 404 error page instead bugs in Symfony4Generating new entities in Symfony4 controllerSymfony4 resource controller
Move up, right, left and down functions
Does friction always oppose motion?
Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?
What's the lunar calendar of two moons
Having to constantly redo everything because I don't know how to do it
Definition of an European Option
How far can gerrymandering go?
Dynamic SQL query - how do I add an int to the code?
Is this house-rule removing the increased effect of cantrips at higher character levels balanced?
Word ending in "-ine" for rat-like
Chandra exiles a card, I play it, it gets exiled again
Does "boire un jus" tend to mean "coffee" or "juice of fruit"?
Can a quantum computer run classical algorithms?
Position representation of spin states and spin operators
Apollo Mission Control Room 2, how do these decimal number displays work?
Fitting large table to single page
Customs and immigration on a USA-UK-Sweden flight itinerary
iMac 2019: Can I mix the old modules with the new ones when upgrading RAM?
"I am [the / an] owner of a bookstore"?
Which high-degree derivatives play an essential role?
Why should I allow multiple IP addresses on a website for a single session?
What is the lowest possible AC?
Why is my 401k manager recommending me to save more?
Is leaving out prefixes like "rauf", "rüber", "rein" when describing movement considered a big mistake in spoken German?
I have a weird bug in controller with Symfony4
Can an ASP.NET MVC controller return an Image?FOSRest Symfony POST using jsonSymfony2 - Dynamic generated form not working while editing formSymfony4 extends controller with route annotationSymfony4 API Controller ParentSymfony4: inject service into controller __construct (constructor)migrating sql query controller symfony4How to display the 404 error page instead bugs in Symfony4Generating new entities in Symfony4 controllerSymfony4 resource controller
This is my controller
$entretien = new Entretien();
$form3 = $this->createForm(EntretienType::class, $entretien); // entretien type has a attribute debutRdv
$form3->add('duree', TimeType::class, [
'placeholder' => [
'hour' => 'Heure', 'minute' => 'Minute', 'second' => 'Seconde',
],
'with_seconds' => true,
"mapped" => false,
]);
$form3->handleRequest($request);
if($form3->isSubmitted())
{
$debutRdv= $entretien->getDebutRdv(); // getdata from form
$duree =$form3->get("duree")->getData();
$duree = $duree->format('PTHHiMsS');
/*------------Here the probleme--------*/
$finRdv = $debutRdv->add(new DateInterval($duree));
/*-------------------------------------*/
...
The problem is when I write $debutRdv->add(...) the attribute $debutRdv changes to $finRdv like I've done $debutRdv = $finRdv;
For example
$debutRdv: "2019-03-25 16:30:00"
$duree : "0:30:00"
When I write this
$finRdv = $debutRdv->add(new DateInterval($duree));
$duree and $debutRdv change to 2019-03-25 17:00:00
but I only want $duree got 2019-03-25 17:00:00
I want to solve this problem because
$entretien->getDebutRdv() also changes to 2019-03-25 17:00:00 Like I have done $entretien->setDebutRdv($duree)
php symfony controller symfony4
add a comment |
This is my controller
$entretien = new Entretien();
$form3 = $this->createForm(EntretienType::class, $entretien); // entretien type has a attribute debutRdv
$form3->add('duree', TimeType::class, [
'placeholder' => [
'hour' => 'Heure', 'minute' => 'Minute', 'second' => 'Seconde',
],
'with_seconds' => true,
"mapped" => false,
]);
$form3->handleRequest($request);
if($form3->isSubmitted())
{
$debutRdv= $entretien->getDebutRdv(); // getdata from form
$duree =$form3->get("duree")->getData();
$duree = $duree->format('PTHHiMsS');
/*------------Here the probleme--------*/
$finRdv = $debutRdv->add(new DateInterval($duree));
/*-------------------------------------*/
...
The problem is when I write $debutRdv->add(...) the attribute $debutRdv changes to $finRdv like I've done $debutRdv = $finRdv;
For example
$debutRdv: "2019-03-25 16:30:00"
$duree : "0:30:00"
When I write this
$finRdv = $debutRdv->add(new DateInterval($duree));
$duree and $debutRdv change to 2019-03-25 17:00:00
but I only want $duree got 2019-03-25 17:00:00
I want to solve this problem because
$entretien->getDebutRdv() also changes to 2019-03-25 17:00:00 Like I have done $entretien->setDebutRdv($duree)
php symfony controller symfony4
add a comment |
This is my controller
$entretien = new Entretien();
$form3 = $this->createForm(EntretienType::class, $entretien); // entretien type has a attribute debutRdv
$form3->add('duree', TimeType::class, [
'placeholder' => [
'hour' => 'Heure', 'minute' => 'Minute', 'second' => 'Seconde',
],
'with_seconds' => true,
"mapped" => false,
]);
$form3->handleRequest($request);
if($form3->isSubmitted())
{
$debutRdv= $entretien->getDebutRdv(); // getdata from form
$duree =$form3->get("duree")->getData();
$duree = $duree->format('PTHHiMsS');
/*------------Here the probleme--------*/
$finRdv = $debutRdv->add(new DateInterval($duree));
/*-------------------------------------*/
...
The problem is when I write $debutRdv->add(...) the attribute $debutRdv changes to $finRdv like I've done $debutRdv = $finRdv;
For example
$debutRdv: "2019-03-25 16:30:00"
$duree : "0:30:00"
When I write this
$finRdv = $debutRdv->add(new DateInterval($duree));
$duree and $debutRdv change to 2019-03-25 17:00:00
but I only want $duree got 2019-03-25 17:00:00
I want to solve this problem because
$entretien->getDebutRdv() also changes to 2019-03-25 17:00:00 Like I have done $entretien->setDebutRdv($duree)
php symfony controller symfony4
This is my controller
$entretien = new Entretien();
$form3 = $this->createForm(EntretienType::class, $entretien); // entretien type has a attribute debutRdv
$form3->add('duree', TimeType::class, [
'placeholder' => [
'hour' => 'Heure', 'minute' => 'Minute', 'second' => 'Seconde',
],
'with_seconds' => true,
"mapped" => false,
]);
$form3->handleRequest($request);
if($form3->isSubmitted())
{
$debutRdv= $entretien->getDebutRdv(); // getdata from form
$duree =$form3->get("duree")->getData();
$duree = $duree->format('PTHHiMsS');
/*------------Here the probleme--------*/
$finRdv = $debutRdv->add(new DateInterval($duree));
/*-------------------------------------*/
...
The problem is when I write $debutRdv->add(...) the attribute $debutRdv changes to $finRdv like I've done $debutRdv = $finRdv;
For example
$debutRdv: "2019-03-25 16:30:00"
$duree : "0:30:00"
When I write this
$finRdv = $debutRdv->add(new DateInterval($duree));
$duree and $debutRdv change to 2019-03-25 17:00:00
but I only want $duree got 2019-03-25 17:00:00
I want to solve this problem because
$entretien->getDebutRdv() also changes to 2019-03-25 17:00:00 Like I have done $entretien->setDebutRdv($duree)
php symfony controller symfony4
php symfony controller symfony4
edited Mar 28 at 14:23
Stephen S
2,3951 gold badge12 silver badges24 bronze badges
2,3951 gold badge12 silver badges24 bronze badges
asked Mar 25 at 16:26
KhalilKhalil
979 bronze badges
979 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This is the default behaviour of DateTime instances: add method changes object it is called from. If you don't want $debutRdv to be changed, you can clone it to $finRdv and apply add:
$finRdv = clone $debutRdv;
// see, here's no `=` as `add()` will directly change `$finRdv`
$finRdv->add(new DateInterval($duree));
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342329%2fi-have-a-weird-bug-in-controller-with-symfony4%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is the default behaviour of DateTime instances: add method changes object it is called from. If you don't want $debutRdv to be changed, you can clone it to $finRdv and apply add:
$finRdv = clone $debutRdv;
// see, here's no `=` as `add()` will directly change `$finRdv`
$finRdv->add(new DateInterval($duree));
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
add a comment |
This is the default behaviour of DateTime instances: add method changes object it is called from. If you don't want $debutRdv to be changed, you can clone it to $finRdv and apply add:
$finRdv = clone $debutRdv;
// see, here's no `=` as `add()` will directly change `$finRdv`
$finRdv->add(new DateInterval($duree));
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
add a comment |
This is the default behaviour of DateTime instances: add method changes object it is called from. If you don't want $debutRdv to be changed, you can clone it to $finRdv and apply add:
$finRdv = clone $debutRdv;
// see, here's no `=` as `add()` will directly change `$finRdv`
$finRdv->add(new DateInterval($duree));
This is the default behaviour of DateTime instances: add method changes object it is called from. If you don't want $debutRdv to be changed, you can clone it to $finRdv and apply add:
$finRdv = clone $debutRdv;
// see, here's no `=` as `add()` will directly change `$finRdv`
$finRdv->add(new DateInterval($duree));
answered Mar 25 at 16:30
u_mulderu_mulder
40k5 gold badges31 silver badges49 bronze badges
40k5 gold badges31 silver badges49 bronze badges
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
add a comment |
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
Its worked thank you, $finRdv = clone $debutRdv; $finRdv=$finRdv->add(new DateInterval($duree));
– Khalil
Mar 25 at 16:40
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342329%2fi-have-a-weird-bug-in-controller-with-symfony4%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown