编辑对象Sonata管理包

时间:2018-03-03 00:17:44

标签: php symfony bundle sonata

我想编辑Parametre对象(OneToOne关联)中包含的子对象Pourcentage但是当我单击编辑时,它会将我重定向到Parametre的版本而不是Pourcentage

我想在我的自定义模板中执行此操作:

<a href="{{ admin.generateObjectUrl('edit', parametre.pourcentage) }}" class="btn btn-sm btn-default edit_link" title="{{ 'action_edit'|trans({}, 'SonataAdminBundle') }}">
                        <i class="fa fa-pencil" aria-hidden="true"></i>
                        {{ 'action_edit'|trans({}, 'SonataAdminBundle') }}
                    </a>

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

class ParametreAdmin extends AbstractAdmin
{
    protected $baseRoutePattern = 'parametre';

    protected function configureFormFields(FormMapper $formMapper)
    {
      $formMapper
            ->add("pourcentage", "sonata_type_admin") 
            ->add("mise", "sonata_type_admin");

      $this->preUpdate($formMapper);
    }

    public function preUpdate($object)
    {
        $entityCreate = $this->getSubject();   
        $user = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
        $entityCreate->setUser($user); 
    }
}


class PourcentageAdmin extends AbstractAdmin
{
    protected $baseRoutePattern = 'pourcentage';

    protected function configureFormFields(FormMapper $formMapper)
    {
       $formMapper
            ->add("pourcentageMise", 'text');
    }  
}