[TYPO3-mvc] 6.2 session handling
Markus Klein
klein.t3 at mfc-linz.at
Sun May 11 21:25:11 CEST 2014
Hi!
If you do this code a normal controller.
In 6.2, the following Code will suffice.
class .... {
/**
* @var Tx_Jpadvisor_Domain_Repository_QuestionRepository
* @inject
*/
protected $questionRepository;
}
No need for extra initialization actions or extra objectmanager magic
Kind regards
Markus
------------------------------------------------------------
Markus Klein
TYPO3 CMS Active Contributors Team Member
> Haverland
> Sent: Sunday, May 11, 2014 9:19 PM
> To: TYPO3 v4 MVC project
> Subject: Re: [TYPO3-mvc] 6.2 session handling
>
> Hi Jacco,
>
> please try the following in your QuestionController instead of:
>
> /**
> *@var Tx_Jpadvisor_Domain_Repository_QuestionRepository
> */
> protected $questionRepository;
>
> protected function initializeAction() {
>
> $this->questionRepository =
> t3lib_div::makeInstance('Tx_Jpadvisor_Domain_Repository_QuestionReposi
> tory');
>
> }
>
> ////////////////////////////////////////////////////////////////
>
> just try this:
>
>
> /**
> *@var Tx_Jpadvisor_Domain_Repository_QuestionRepository
> *@inject
> */
> protected $questionRepository;
>
>
>
> Then you could omit your initializeAction.
>
>
> In the same way you could inject an ObjectManager or your SessionHandler.
>
> With the ObjectManager you could also get an instance of your
> SessionHandler.
>
> Best regards
>
> Björn
>
>
>
>
> Am 11.05.2014 20:37, schrieb Jacco van der Post:
> > Hi Bjoern,
> >
> > I am not an hero in building extensions and this one I built couple
> > years back and works in 4.7.
> >
> > I am not even sure if the objectManager needs to get injected. I just
> > want to be able to use the class SessionHandler.php, a t3lib_Singleton.
> >
> > Error : http://dev62.typo3-dev.com/index.php?id=6
> >
> > Code now :
> >
> > class Tx_Jpadvisor_Domain_Repository_QuestionRepository extends
> > Tx_Extbase_Persistence_Repository {
> >
> > protected $defaultOrderings = array(
> > 'sorting' =>
> > Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING
> > );
> >
> > /**
> > * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
> > */
> > protected $objectManager;
> >
> > /**
> > * The session handler
> > * @var Tx_Jpadvisor_Domain_Session_SessionHandler
> > *
> > */
> > protected $sessionHandler;
> >
> > /**
> > * Injects the object manager
> > *
> > * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
> > $objectManager
> > * @return void
> > */
> > public function
> >
> injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterfac
> e
> > $objectManager) {
> > $this->objectManager = $objectManager;
> > }
> >
> > /**
> > * @param Tx_Jpadvisor_Domain_Session_SessionHandler
> $sessionHandler
> > * @return void
> > */
> > public function
> > injectSessionHandler(Tx_Jpadvisor_Domain_Session_SessionHandler
> > $sessionHandler) {
> > $this->sessionHandler =
> > $this->objectManager-
> >get('Tx_Jpadvisor_Domain_Session_SessionHandler');
> > }
> >
> >
> >
> >
> >
> > This does not give the above error and the session stuf seems to work.
> >
> > public function __construct() {
> > $this->objectManager =
> >
> \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbas
> e\Object\ObjectManager');
> > $this->sessionHandler =
> > $this->objectManager-
> >get('Tx_Jpadvisor_Domain_Session_SessionHandler');
> > }
> >
> > However than I get Fatal error when trying a findAll()
> >
> > Call to a member function createQueryForType() on a non-object in
> > /html/sources/typo3_src-6.2.2/typo3/sysext/extbase/Classes/Persistence
> > /Repository.php
> > on line 265
> >
> >
> > Thanks a lot.
> >
> >
> >
> >
> > Bjoern Haverland schreef op 11-5-2014 20:09:
> >
> >> occurs the error in the calling controller or directly in the
> >> repository? How does your controller inject the repository?
> >>
> >
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
More information about the TYPO3-project-typo3v4mvc
mailing list