9
Tôi đang cố gắng thêm một hành động trong gói quản trị sonata. Tôi đã thay đổi lớp quản lý của tôi với:Thêm hành động trong SonataAdminBundle
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
// add custom action links
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'calculate' => array('template' => 'myappMyBundle:Admin:list__action_calculate.html.twig'),
'edit' => array(),
)
))
;
}
và
protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null)
{
if (!$childAdmin && !in_array($action, array('edit'))) {
return;
}
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
$menu->addChild('calculate', array('uri' => 'http://google.com?id=' . $id));
}
và đưa một mẫu gọi là list__action_calculate.html.twig trong src/myapp/MyBundle/Resources/views/Admin /:
{% if admin.isGranted('EDIT', object) and admin.hasRoute('edit') %}
<a href="{{ admin.generateObjectUrl('calculate', object) }}" class="calculate_link" title="{{ 'action_calculate'|trans({}, 'SonataAdminBundle') }}">
<img src="{{ asset('bundles/sonataadmin/famfamfam/page_white_edit.png') }}" alt="{{ 'action_calculate'|trans({}, 'SonataAdminBundle') }}" />
</a>
{% endif %}
Nhưng tôi gặp lỗi này từ symfony:
An exception has been thrown during the rendering of a template
("unable to find the route `mysite.mybundle.admin.myentity.calculate`")
in "SonataAdminBundle:CRUD:list.html.twig"
Tôi đã bỏ lỡ điều gì? Có một đầu mối trong tài liệu hướng dẫn hơn trang này của Doc không.
chính thức tài liệu hướng dẫn: [Tác vụ hàng loạt] (http://sonata-project.org/bundles/admin/2-2/doc/reference/batch_actions.html) –
Tài liệu mới sẽ được gửi od, cảm ơn bạn đã cập nhật. – user1254498