DateTimeBundle icon indicating copy to clipboard operation
DateTimeBundle copied to clipboard

Integration with SonataAdminBundle

Open motammem opened this issue 9 years ago • 1 comments

Hi there I was trying to integrate it with SonataAdminBundle in list filter section but I don't know much about their structure. It says " No attached service to type named mohebifar_datetime" It will be great if you can handle this too. Thanks for your great bundle.

motammem avatar Sep 05 '14 18:09 motammem

install the bundle :

https://github.com/mohebifar/DateTimeBundle/blob/master/Resources/doc/1.1-installation.md

add

 protected function configureListFields(ListMapper $listMapper)
    {
....
        $listMapper
->add('_action', 'date_filter', array(
                'actions' => array(
                    //'show' => array(),
                    'action' => array('template' => 'SomeBundlename:some_template.html.twig'),
                )
-------
}

in SomeBundlename:some_template.html.twig add

{{ object.date|date_format('Y-m-d H:i:s') }}

object is actual object name pass throw filter to template so dont change the name but date is depend on your object on list maybe exp :

order.created_at is showing your date on list

then it will be

{{ object.created_at|date_format('Y-m-d H:i:s') }}

for better solution you can use this :

->add('created_at', null, array('template' => 'pdate.html.twig'))

pdate.html.twig :

 <td>{{ object.createdAt|date_format('l jS F Y H:i:s') }}</td> 

roozbeh360 avatar Dec 06 '14 06:12 roozbeh360