Question

I'm attempting to incorporate the multi-user bundle into a project and get

Error: Call to undefined method Vol\VolBundle\Entity\Staff::setEnabled() in G:\Documents\workspace\volunteer\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Controller\RegistrationController.php line 44

FOSUserBundle appeared to behave correctly before adding the multi-user bundle. At least some of the relevant code:

User entity (named Person)

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;
...
}

Staff entity:

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;
...
}

config.yml

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

routing.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 }
Was it helpful?

Solution

The error is thrown from the FOS\UserBundle\Controller\RegistrationController.php. So, let's take a look inside it, at line 44:

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

It is trying to call to the setEnabled function which is required to be defined in the Staff class. So, you just need to make the Staff class extends BaseUser as you did with the Person class.

Staff Entity:

use FOS\UserBundle\Model\User as BaseUser;
class Staff extends BaseUser{

}

It should work fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top