我使用Sonata Admin,在列表实体中我需要添加自定义操作,我确实喜欢奏鸣曲文档screen,但是当我使用过滤字段或点击页面时,screen,分页我的操作消失了,我有按钮选择。如何添加自定义操作以及如何使其不丢失?
<service id="sonata.admin.developer" class="Artel\AdminBundle\Controller\DeveloperSonataController">
<tag name="sonata.admin" manager_type="orm" group="Content" label="Developer"/>
<argument />
<argument>Artel\ProfileBundle\Entity\Developer</argument>
<argument>ArtelAdminBundle:CRUD</argument>
<argument />
<call method="setTranslationDomain">
<argument>ArtelAdminBundle</argument>
</call>
<call method="addChild">
<argument type="service" id="sonata.news.admin.comment" />
</call>
</service>
添加服务CRUD
{# src/AppBundle/Resources/views/CRUD/list__action_clone.html.twig #}
//<a class="btn btn-sm" href="{{ admin.generateObjectUrl('clone', object) }}">clone</a>
创建模板
class DeveloperSonataController extends Admin
{
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('clone', $this->getRouterIdParameter().'/clone');
}
添加路由
class DeveloperSonataController extends Admin
{
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('clone', $this->getRouterIdParameter().'/clone');
}
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('firstName', null, array('label' => 'Developer\'s First Name', 'max_length' => 255))
->add('lastName', null, array('label' => 'Developer\'s Last Name', 'max_length' => 255))
->add('qualification', 'choice', array('label' => 'Speciality',
'choices' => array('Frontend' => 'Frontend', 'Backend' => 'Backend', 'Full stack' => 'Full stack'),'attr'=> array('class'=>'qualif'), 'required' => false))
->add('level', 'choice', array('label' => 'Professional Level', 'max_length' => 255,
'choices' => array('Junior' => 'Junior', 'Middle' => 'Middle', 'Senior' => 'Senior')))
->add('tags', 'tags', array('label' => 'Tags','required' => false))
->add('main_skill', 'mainSkill', array('label' => 'Main Skill', 'required' => true, 'mapped' => true, 'attr' => array('placeholder' => 'Select your skills ...', 'class'=>'main_skill') ))
->add('skills', 'skills', array('label' => 'Skills','required' => false))
->add('english', 'choice', array('label' => 'English Level', 'max_length' => 255,
'choices' => array('Basic' => 'Basic', 'Intermediate' => 'Intermediate', 'Advanced' => 'Advanced')))
->add('rate', null, array('label' => 'Rate $/h', 'max_length' => 255))
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('email')
->add('telephone')
->add('skype')
->add('username')
->add('firstName')
->add('lastName')
->add('main_skill')
->add('skills')
->add('level')
->add('rate')
->add('english')
->add('location')
->add('country')
->add('created', 'doctrine_orm_date_range', array('field_type'=>'sonata_type_date_range_picker',))
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')//how change routig in addIdentifier??
->add('username')
->add('firstName')
->add('lastName')
->add('main_skill')
->add('level')
->add('rate')
->add('english')
->add('email')
->add('location')
->add('country')
->add('created')
->add('image', 'string', array('template' => 'SonataMediaBundle:MediaAdmin:list_image.html.twig'))
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'clone' => array(
'template' => 'ArtelAdminBundle:CRUD:list__action_clone.html.twig'
)
)
))
;
}
并且在完成后我有控制器
{{1}}
}