[TYPO3-mvc] "Call to a member function attach() on a non-object" when using addUserGroup()

Sebastian Schreiber me at schreibersebastian.de
Wed Mar 7 11:30:36 CET 2012


Hi Christian,
first of all, use the ObjectManager to create or get new / shared 
instances of an object.
So instantiate your userGroupRepository the following way:
$userGroupRepository = 
$this->objectManager->get('Tx_Extbase_Domain_Repository_FrontendUserGroupRepository');

But your problem lies somewhere else.
Did you overwrite the __constructor method in your class new 
Tx_Kbs_Domain_Model_User()?
if so, did you call the parent constructor method with 
parent::__constructor($username = '', $password = '');



Am 07.03.2012 11:18, schrieb Christian Essl:
> Hi
>
>
>
>    Extbase is driving me crazy here.... I try to create a new user and add an existing userGroup:
>
>      if(!is_object($user))
>
>      {
>
>              $newUser = new Tx_Kbs_Domain_Model_User();
>
>              // set the userData
>
>              $userGroupRepository = t3lib_div::makeInstance('Tx_Extbase_Domain_Repository_FrontendUserGroupRepository');
>
>              $userGroup = $userGroupRepository->findByUid(3);
>
>              $newUser->addUserGroup($userGroup);
>
>              $this->userRepository->add($newUser);
>
>      }
>
>      The groups Record Type is set to "Tx_Extbase_Domain_model_FrontendUserGroup".
>
>      Now when I try to attach the UserGroup by "addUserGroup", I get the following error:
>
>      Call to a member function attach() on a non-object in /usr/www/users/ltcdwu/typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php on line 215
>
>      What is wrong there? There obviously is a UserGroup with uid 3.
>
>      The new Users Record Type is set to the one from my extension. (Not to "Tx_Extbase_Domain_model_FrontendUser) Maybe this is the problem?
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


-- 
Sebastian Schreiber
(Medieninformatiker B.Sc.)
(TYPO3 Certified Integrator)

Schanzenstraße 27, Schlosserei 4
D-51063 Köln

T  0221 677 88 541
M  0176 431 05 790

Skype schreibersebastian.de

me at schreibersebastian.de
www.schreibersebastian.de

Steuernummer: 217 / 5269 / 4675



More information about the TYPO3-project-typo3v4mvc mailing list