New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object of class DateTime could not be converted to string #737
Comments
I have the same after new update. I am using 2.0 branches and has this error with datetime list type:
I don't know if something changed in Doctrine and is connected with __toString() |
The problem is in the SonataIntlBundle. The 2.0 branch doesn't have the twig files for rendering (referenced here https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/2.0/DependencyInjection/SonataDoctrineORMAdminExtension.php#L114) Some fixes:
|
This works for me. But I'm not sure how it will affect other components
I'm now at master branch, but it seems like AdminBundle just ignores these templates. I checked defaultsArray. It's correct. |
It's an optional bundle, everything should work normally if you remove it. Some internationalization features are not going to be available. |
Ok, thx for your help =) |
@JohnPoison is the field declared as DateTime in your doctrine definition ? if not you need to set the field type as second argument. |
@rande fields:
startDate:
type: date ... |
bumping, DateTime can not be rendered on 2.1 |
Still not fixed for Symfony 2.1.3. Continue to see this error in a list view: An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class DateTime could not be converted to string in MyProject/app/cache/dev/twig/c8/ba/c455cc2ad87a1b1e1f5964432bbb.php line 54") in "SonataAdminBundle:CRUD:list.html.twig". Additionally, base_list_field.html.twig doesn't appear to pull in list_datetime.html.twig |
@bigcalm , please make sure that you're using correct entity field naming in $list->add. If you have, e.g. In my case the issue has been fixed by forcibly removing doctrine proxy classes and re-generating custom repositories. |
Well, now I just feel like an idiot :) Thank you @andrewtch that fixed it. |
Hi, This is because at https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/2.0/DependencyInjection/SonataDoctrineORMAdminExtension.php#L114 the strategy to decide if load intl templates or not is implemented with class_exists that in such situation returns true. Now if you look at https://github.com/sonata-project/SonataAdminBundle/blob/2.0/Twig/Extension/SonataAdminExtension.php#L74 you can see that Twig will throws the exception (because SonataIntlBundle isn't enabled) and so will be used the base_list_field.html.twig template that will try to convert a DateTime in string. |
Thanks @mmenozzi your solution works. This should be stated in the documentation, because it cause very frustrating errors in the very early stage of the development. |
You're welcome. ;) |
This error still happens when you try to use a datetime field as The field is defined as datetime in the related entity: /**
* @var \DateTime
*
* @ORM\Column(name="endTime", type="datetime", nullable=true)
*/
private $endTime; and added to list fileds like this: >add('solvingLog', 'entity', array('label' => 'End date', 'associated_property' => 'endTime')) And i get the same error message. I have installed the SonataIntlBundle and enabled it in AppKernel.php. Any ideas what could be wrong? |
I figured out the cause of my problem and submitted an issue to the SonataDoctrineORMAdminBundle: |
Although you can use the
result Solution view http://stackoverflow.com/questions/render-datetime |
I have this error in listAction when adding field that has orm type date or datetime. Has anyone idea how to fix this?
Render fails on 20 string of base_list_field.htm.twig. Object passes here instead of string.
I have no clue where to look for reason of error. Maybe some kind of a data transformer missing
The text was updated successfully, but these errors were encountered: