0

My problem is that I want to set a value to one field of an Entity and this value comes from a form.

The form is bound to another entity and this field of the form is named fmedida.

This is what I've tried

$hijo-> setFinicio(new \DateTime($form->getData()->getfmedida()));

But of course the syntax is not correct since I have this error message:

"DateTime::__construct() expects parameter 1 to be string, object given"

1
  • Is the data in fmedida a date? Commented Aug 22, 2013 at 10:53

1 Answer 1

2

I advise you to var_dump the value that you get from $form->getData()->getfmedida() and see what is happening.

When I tried getData(), it returns array on my side, so also try:

$data = $form->getData();
$fmedida = $data['fmedida'];

$hijo-> setFinicio(new \DateTime($fmedida));

Also, DateTime creates DateTime objects from strings. Obviously, the value which you are getting from $form->getData()->getfmedida() is not a string, it's a object. If $form->getData()->getfmedida() gives you a DateTime object, I can't see a point in using DateTime, so just

$hijo-> setFinicio($form->getData()->getfmedida());

should be enough.

Sign up to request clarification or add additional context in comments.

1 Comment

It was your last option gracias!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.