私はsonata adminのチュートリアルに従いましたが、メニューを生成しますが、すべてが "デフォルト"グループの下にあります。 "ユーザー"、 "イベント"などの新しいグループを追加したいと思います。管理グループとアイテムをsymfonyのソナタ管理者に追加します
私はhttps://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_knp_menu.html#extending-the-menu上で見つけたやろう:
<?php
namespace AppBundle\EventListener;
use Sonata\AdminBundle\Event\ConfigureMenuEvent;
/**
* Description of AdminMenuBuilderListener
*
* @author christophe
*/
class AdminMenuBuilderListener {
public function addMenuItems(ConfigureMenuEvent $event)
{
$menu = $event->getMenu();
$child = $menu->addChild('reports', array(
'route' => 'admin_app_category_index',
'labelAttributes' => array('icon' => 'fa fa-bar-chart'),
));
$child->setLabel('Daily and monthly reports');
}
}
のrouting.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
services.yml
parameters:
# parameter_name: value
services:
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
admin.blog_post:
class: AppBundle\Admin\BlogPostAdmin
arguments: [~, AppBundle\Entity\BlogPost, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Blog post }
app.menu_listener:
class: AppBundle\EventListener\AdminMenuBuilderListener
tags:
- { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: addMenuItems }
CategoryAdmin.php
<?php
namespace AppBundle\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class CategoryAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('name', 'text');
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('name');
}
}
実際には私には例外がスローされます:Unable to generate a URL for the named route "admin_app_category_index" as such route does not exist
。私はsymfonyを非常に新しくしています。この場合、ルートがどのように生成されるのか分かりません。
助けを歓迎します。
services:
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category , group : Blog}
admin.blog_post:
class: AppBundle\Admin\BlogPostAdmin
arguments: [~, AppBundle\Entity\BlogPost, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Blog post, group : Blog }
admin.user:
class: AppBundle\Admin\UserAdmin
arguments: [~, AppBundle\Entity\User, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: List, group : Users }
admin.group:
class: AppBundle\Admin\GroupAdmin
arguments: [~, AppBundle\Entity\group, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Groups, group : Users }
あなたは管理者メニューにグループを追加することを許可group
を見ることができます: