我正在尝试将多用户捆绑包合并到项目中并获取
错误:调用未定义的方法 Vol \ VolBundle \ Entity \ Staff :: setEnabled()in G:\文件\工作空间\志愿者\厂商\ friendsofsymfony \用户束\ FOS \ UserBundle \控制器\ RegistrationController.php 第44行
在添加多用户捆绑包之前,FOSUserBundle似乎表现正常。至少有一些相关的代码:
namespace Vol\VolBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Vol\VolBundle\Validator\Constraints as V2Assert;
use FOS\UserBundle\Model\User as BaseUser;
/**
* Person
*
* @ORM\Table(name="person")
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"staff" = "Staff", "volunteer" = "Volunteer"})
*/
Abstract class Person extends BaseUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
...
}
namespace Vol\VolBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Staff
*
* @ORM\Table(name="staff")
* @ORM\Entity(repositoryClass="Vol\VolBundle\Entity\StaffRepository")
* @UniqueEntity(fields = "username", targetClass = "Vol\VolBundle\Entity\Person", message="fos_user.username.already_used")
* @UniqueEntity(fields = "email", targetClass = "Vol\VolBundle\Entity\Person", message="fos_user.email.already_used")
*/
class Staff
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
...
}
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Vol\VolBundle\Entity\Person
# registration:
# form:
# type: vol_user_registration
service:
user_manager: pugx_user_manager
pugx_multi_user:
users:
staff:
entity:
class: Vol\VolBundle\Entity\Staff
# factory:
registration:
form:
type: Vol\VolBundle\Form\RegistrationStaffFormType
name: fos_user_registration_form
validation_groups: [Registration, Default]
template: VolVolBundle:Registration:staff.form.html.twig
profile:
form:
type: Vol\VolBundle\Form\ProfileStaffFormType
name: fos_user_profile_form
validation_groups: [Profile, Default]
volunteer:
entity:
class: Vol\VolBundle\Entity\Volunteer
registration:
form:
type: Vol\VolBundle\Form\RegistrationVolunteerFormType
template: VolVolBundle:Registration:volunteer.form.html.twig
profile:
form:
type: Vol\VolBundle\Form\ProfileVolunteerFormType
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 }
答案 0 :(得分:-1)
FOS\UserBundle\Controller\RegistrationController.php引发错误。那么,让我们看一下第44行:
class RegistrationController extends ContainerAware
{
public function registerAction(Request $request)
{
$user->setEnabled(true); // Line 44
}
它正在尝试调用setEnabled
类中需要定义的Staff
函数。因此,您只需要像Staff
类那样使BaseUser
类扩展Person
。
员工实体:
use FOS\UserBundle\Model\User as BaseUser;
class Staff extends BaseUser{
}
它应该可以正常工作。