【发布时间】:2015-02-27 08:50:24
【问题描述】:
我正在使用 Symfony 和 Sonata Bundle 来生成我的管理界面。我有 3 节课:
- 餐厅
- 服务
- 餐厅服务
类 Restaurant 和 Service 与 RestaurantService 有 OneToMany 关系。
我尝试RestaurantService 作为餐厅的儿童管理员,但我遇到了这些错误:
RestaurantAdmin.php 第 143 行中的 ContextErrorException:
运行时通知:声明 GSG\AdminBundle\Admin\RestaurantAdmin::configureSideMenu() 应该是 兼容 Sonata\AdminBundle\Admin\Admin::configureSideMenu(Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = 空)
和
classes.php 第 13757 行中的 FileLoaderLoadException:
运行时通知:声明 GSG\AdminBundle\Admin\RestaurantAdmin::configureSideMenu() 应该是 兼容 Sonata\AdminBundle\Admin\Admin::configureSideMenu(Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) 在 /Volumes/Data/ge0ra/www/admin_gsg/app/config/ 中。 (这是 进口自 “/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')
;
}
}
有人知道这些错误可能来自哪里吗?
谢谢!
【问题讨论】:
标签: php symfony parent-child sonata-admin