我使用Symfony和Sonata Bundle来生成我的管理界面。我有3个班级:
课程餐厅和服务与餐厅服务有一个OneToMany关系。
我在餐厅尝试使用RestaurantService作为儿童管理员,但我发现了这些错误:
ContextErrorException in RestaurantAdmin.php line 143: Runtime Notice: Declaration of GSG\AdminBundle\Admin\RestaurantAdmin::configureSideMenu() should be compatible with Sonata\AdminBundle\Admin\Admin::configureSideMenu(Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL)
和
FileLoaderLoadException in classes.php line 13757: Runtime Notice: Declaration of GSG\AdminBundle\Admin\RestaurantAdmin::configureSideMenu() should be compatible with Sonata\AdminBundle\Admin\Admin::configureSideMenu(Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in /Volumes/Data/ge0ra/www/admin_gsg/app/config/. (which is being imported from "/Volumes/Data/ge0ra/www/admin_gsg/app/config/routing.yml").
这是我的services.yml文件:
services: sonata.admin.restaurant: class: GSG\AdminBundle\Admin\RestaurantAdmin tags: - { name: sonata.admin, manager_type: orm, group: "Gestion des restaurants", label: "Restaurants" } arguments: - ~ - GSG\AdminBundle\Entity\Restaurant - ~ calls: - [ addChild, [@sonata.admin.restaurantservice]] sonata.admin.service: class: GSG\AdminBundle\Admin\ServiceAdmin tags: - { name: sonata.admin, manager_type: orm, group: "Gestion des restaurants", label: "Services" } arguments: - ~ - GSG\AdminBundle\Entity\Service - ~ sonata.admin.restaurantservice: class: GSG\AdminBundle\Admin\RestaurantServiceAdmin tags: - { name: sonata.admin, manager_type: orm, group: "Gestion des restaurants", label: "RestaurantServices" } arguments: - ~ - GSG\AdminBundle\Entity\RestaurantService - ~
在我的RestaurantAdmin课程中:
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null) { if (!$childAdmin && !in_array($action, array('edit'))) { return; } $admin = $this->isChild() ? $this->getParent() : $this; $id = $admin->getRequest()->get('id'); $menu->addChild( 'Voir/Editer', array('uri' => $admin->generateUrl('edit', array('id' => $id))) ); $menu->addChild( 'Services', array('uri' => $admin->generateUrl('sonata.admin.restaurantservice.list', array('id' => $id))) ); }
和我的RestaurantServiceAdmin类:
class RestaurantServiceAdmin extends Admin { protected $parentAssociationMapping = 'Restaurant'; // Fields to be shown on create/edit forms protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('service', 'sonata_type_model') ; } // Fields to be shown on filter forms protected function configureDatagridFilters(DatagridMapper $datagridMapper) { } // Fields to be shown on lists protected function configureListFields(ListMapper $listMapper) { if (!$this->isChild()) $listMapper->addIdentifier('id')->addIdentifier('Restaurant'); $listMapper ->add('service', 'sonata_type_model') ; } }
有人知道这些错误可能来自哪里吗?
谢谢!
答案 0 :(得分:0)
RestaurantAdmin
类的第一个参数configureSideMenu
设置为MenuItemInterface $menu
时,它应该是\Knp\Menu\ItemInterface
的实例。
类型提示的Menu
部分是错误的。