FOS用户更新错误

时间:2016-09-13 11:36:23

标签: php symfony fosuserbundle sonata

我正在与Sonata合作开展Symfony 2,8项目。 我发现用户使用FOS进行管理:

namespace Voyage\AdminBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;

class UserCoreAdmin extends Admin {

    /**
     * {@inheritdoc}
     */
    public function getFormBuilder() {
        //...
    }

    /**
     * {@inheritdoc}
     */
    public function getExportFields() {
        // avoid security field to be exported
    }

    /**
     * {@inheritdoc}
     */
    protected function configureListFields(ListMapper $listMapper) {
        //...
    }

    /**
     * {@inheritdoc}
     */
    protected function configureDatagridFilters(DatagridMapper $filterMapper) {
       //...
    }

    /**
     * {@inheritdoc}
     */
    protected function configureShowFields(ShowMapper $showMapper) {
    //...
    }

    /**
     * {@inheritdoc}
     */
    protected function configureFormFields(FormMapper $formMapper) {
        //...
    }
    /**
     * {@inheritdoc}
     */
    public function preUpdate($user) {
        $this->getUserManager()->updateCanonicalFields($user);
        $this->getUserManager()->updatePassword($user);
    }
    /**
     * @param UserManagerInterface $userManager
     */
    public function setUserManager(UserManagerInterface $userManager) {
        $this->userManager = $userManager;
    }
    /**
     * @return UserManagerInterface
     */
    public function getUserManager() {
        return $this->userManager;
    }
}

我在进行用户更新时遇到此错误:

  

注意:未定义的属性:   航程\ AdminBundle \管理\ UserCoreAdmin :: $的UserManager

     

500内部服务器错误 - ContextErrorException

2 个答案:

答案 0 :(得分:0)

你应该扩展Sonata\UserBundle\Admin\Entity\UserAdmin,它应该具有此属性,而不是Sonata\AdminBundle\Admin\Admin

答案 1 :(得分:0)

在services.yml中缺少配置,缺少对SetUserManager的调用。

- [ setUserManager, [ @fos_user.user_manager]]