PUGXMultiUserBundle: undefined method setEnabled() in FOSUs



我正在尝试将多用户捆绑包合并到项目中并获得

错误:调用未定义的方法 Vol\VolBundle\Entity\Staff::setEnabled() in G:\Documents\workspace\volunteer\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Controller\RegistrationController.php 44号线

FOSUserBundle在添加多用户捆绑包之前似乎行为正确。至少一些相关的代码:

用户实体(命名人员)

namespace VolVolBundleEntity;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use VolVolBundleValidatorConstraints as V2Assert;
use FOSUserBundleModelUser as BaseUser;
/**
 * Person
 *
 * @ORMTable(name="person")
 * @ORMEntity
 * @ORMInheritanceType("JOINED")
 * @ORMDiscriminatorColumn(name="type", type="string")
 * @ORMDiscriminatorMap({"staff" = "Staff", "volunteer" = "Volunteer"})
 */
Abstract class Person extends BaseUser
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer", nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    protected $id;
...
}

员工实体:

namespace VolVolBundleEntity;
use DoctrineORMMapping as ORM;
use PUGXMultiUserBundleValidatorConstraintsUniqueEntity;
use SymfonyComponentValidatorConstraints as Assert;
/**
 * Staff
 *
 * @ORMTable(name="staff")
 * @ORMEntity(repositoryClass="VolVolBundleEntityStaffRepository")
 * @UniqueEntity(fields = "username", targetClass = "VolVolBundleEntityPerson", message="fos_user.username.already_used")
 * @UniqueEntity(fields = "email", targetClass = "VolVolBundleEntityPerson", message="fos_user.email.already_used")
 */
class Staff
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer", nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $id;
...
}

配置.yml

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: VolVolBundleEntityPerson
#    registration:
#        form:
#            type: vol_user_registration
    service:
        user_manager: pugx_user_manager
pugx_multi_user:
  users:
    staff:
        entity: 
          class: VolVolBundleEntityStaff
#          factory: 
        registration:
          form: 
            type: VolVolBundleFormRegistrationStaffFormType
            name: fos_user_registration_form
            validation_groups:  [Registration, Default]
          template: VolVolBundle:Registration:staff.form.html.twig
        profile:
          form:
            type: VolVolBundleFormProfileStaffFormType
            name: fos_user_profile_form
            validation_groups:  [Profile, Default] 
    volunteer:
        entity: 
          class: VolVolBundleEntityVolunteer
        registration:
          form: 
            type: VolVolBundleFormRegistrationVolunteerFormType
          template: VolVolBundle:Registration:volunteer.form.html.twig
        profile:
          form: 
            type: VolVolBundleFormProfileVolunteerFormType

路由.yml:

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile
#rem'd for PUGX multi-user bundle
#fos_user_register:
#    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
#    prefix: /register
fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting
fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile
##add following for PUGX multi-user bundle
staff_registration:
    pattern:  /register/staff
    defaults: { _controller: VolVolBundle:RegistrationStaff:register }
volunteer_registration:
    pattern:  /register/volunteer
    defaults: { _controller: VolVolBundle:RegistrationVolunteer:register }

错误是从 FOS\UserBundle\Controller\RegistrationController.php 引发的。那么,让我们来看看它的内部,在第 44 行:

class RegistrationController extends ContainerAware
{
    public function registerAction(Request $request)
    {
        $user->setEnabled(true); // Line 44
}

它正在尝试调用需要在 Staff 类中定义的 setEnabled 函数。因此,您只需要使Staff类扩展BaseUser就像Person类一样。

员工实体:

use FOSUserBundleModelUser as BaseUser;
class Staff extends BaseUser{
}

它应该可以正常工作。

相关内容

  • 没有找到相关文章

最新更新