php - addRole() Error - Call to a member function addRole() on a non-object -
I am currently adding the role of using Symfony2 / FOSUserBundle in a user account.
Example, and the previous SO questions I have in my controller are:
Namespace MyVendor \ MyBundle \ Controller; Use Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller; Use MyVendor \ MyBundle \ Entity \ Account; Use Symfony \ Component \ HttpFoundation \ Request; Square DefaultController Controller {Personal Function AddRole ($ role, $ user name) Expands {// ARI Manager $ em = $ this- & gt; GetDoctrine () - & gt; GetManager (); // name admin $ dbuser = $ em- & gt; Get user with recipient ("MyVendor \ UserBundle \ Entity \ User") - & gt; FindBy (array ("user name" => gt; $ username)); // role $ dbuser- & gt; Set addRole ('ROLE_BASIC_TRIAL'); // database $ em-> Continue ($ dbuser); $ Em- & gt; Flush (); }
However, after running the method, I receive the following error:
FatalErrorException: Error: Call addRole () on a non-object member function In ..... \ MyVendor \ MyBundle \ Controller \ DefaultController.php line 52
If I've missed something obvious - this is my first Symfony2 project.
findBy () returns an array. Try changing it with FindOneBy ()
Comments
Post a Comment