[TYPO3-UG Italy] Aggiungere un fe_group in fase di creazione di un fe_user
Gianpaolo Scrigna
letsjump at gmail.com
Mon Mar 10 17:03:34 CET 2014
Mauro grazie! Funziona!!!
Ci ho sbattuto la testa per ore e non avevo visto la questione da questa
prospettiva!
grazie a te e tutta la community T3 Italy
Gianpaolo
Il giorno 10 marzo 2014 16:52, Mauro Lorenzutti <
mauro.lorenzutti at webformat.com> ha scritto:
> Ciao Gianpaolo,
>
> ad un utente di frontend possono essere associati N gruppi di frontend, la
> relazione è molti a molti, non 1:1.
> Prova a sostituire il codice seguente:
>
> $user->setUsergroup($groupObj);
>
> con
>
> $user->addUsergroup($groupObj);
>
> Ciao,
> --
>
> Mauro Lorenzutti
>
> CTO / Software Architect
> mauro.lorenzutti at webformat.com
> Tel. +39-0427-926.389
>
> WEBFORMAT srl -- www.webformat.com
> Via Mecenate, 76 - 20138 MILANO
> Corte Europa, 12 - 33097 SPILIMBERGO (PN)
>
> *** TYPO3 Certified Integrator *** - *** Magento Certified Developer ***
>
>
>
>
> Il 10/03/2014 16:17, Gianpaolo Scrigna ha scritto:
>
> Ciao a tutti.
>> Sto sviluppando una estensione personalizzata per typo3 > 6.1 con extbase.
>> Tra le varie cose, crea un nuovo fe_user in base ai dati ricevuti da una
>> form.
>> Tutto bene finchè non tento di assegnargli un fe_group predefinito.
>> Ecco il repository:
>>
>> class WizardRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
>> {
>> /**
>> * frontEndUserRepository
>> *
>> * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
>> * @inject
>> */
>> protected $frontEndUserRepository;
>>
>> /**
>> * frontEndUserGroup
>> *
>> * @var \TYPO3\CMS\Extbase\Domain\Repository\
>> FrontendUserGroupRepository
>> * @inject
>> */
>> protected $frontEndUserGroupRepository;
>>
>> /**
>> * persistence manager
>> *
>> * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
>> * @inject
>> */
>> protected $persistenceManager;
>>
>> /**
>> * instanzia la sessione
>> *
>> * @return
>> */
>> public function __construct() {
>> session_start();
>> parent::__construct();
>> }
>>
>> ... altri metodi ...
>>
>> public function addFeUser($array, $settings) {
>>
>> $user = new $this->frontEndUserRepository;
>>
>> $user->setEmail($args['p-email']);
>> $user->setUsername($args['p-email']);
>> $user->setName($args['p-nome']);
>> ...
>> $groupObj = $this->frontEndUserGroupRepository->
>> findOneByUid(2);
>> $user->setUsergroup($groupObj);
>>
>> $add = $this->frontEndUserRepository->add($user);
>>
>> $this->persistenceManager->persistAll();
>>
>> return $user;
>> }
>>
>> Commentando la riga $user->setUsergroup($groupObj); l'utente viene
>> correttamente scritto a DB e restituito dal metodo, invece tentando di
>> assegnargli il gruppo ottengo l'errore
>>
>> *#1: PHP Catchable Fatal Error: Argument 1 passed to
>> TYPO3\CMS\Extbase\Domain\Model\FrontendUser::setUsergroup() must be an
>> instance of TYPO3\CMS\Extbase\Persistence\ObjectStorage, instance of
>> TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup given, called in
>> /home/www/mydir/typo3conf/ext/myext/Classes/Domain/
>> Repository/WizardRepository.php
>> on line 191 and defined in
>> /home/letsjump/www/0-LIBS/typo3/typo3_src-6.1.7/typo3/
>> sysext/extbase/Classes/Domain/Model/FrontendUser.php
>> line 200*
>>
>> Dove sbaglio? Qualcuno ha esperienza nell'instanziare oggetti con
>> objectManager e namespaces? In giro trovo poca documentazione e molto
>> confusa.
>>
>> Grazie in anticipo!
>> _______________________________________________
>> TYPO3-UG-Italy mailing list
>> TYPO3-UG-Italy at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-ug-italy
>>
>
>
>
> _______________________________________________
> TYPO3-UG-Italy mailing list
> TYPO3-UG-Italy at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-ug-italy
>
More information about the TYPO3-UG-Italy
mailing list