How can I get the type of current user with PUGXMultiUserBundle ? This code returns this error
{% if app.user.type == 'user_one' %}
//...
{% endif %}
This is the error
Method "type" for object "AppBundle\Entity\UserOne" does not exist
This is entity User
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="user")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"user_one" = "UserOne", "user_two" = "UserTwo"})
*
*/
abstract class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
after updating database there is a new field named type created in table user
Ah, I see the problem. In the twig file, you are calling:
{% if app.user.type == 'user_one' %}
Where "app.user" specifies the object, and "type" specifies the method. But you don't have a "method" defined in the Class. But instead you have the DiscriminatorColumn.
A method would be something like:
public function type(){
...
}
Hopefully that makes sense.