[TYPO3-mvc] Extending Tx_Extbase_Domain_Model_FeUser with some kind of session object
Thomas "Thasmo" Deinhamer
thasmo at gmail.com
Wed Jan 13 20:35:19 CET 2010
Imho there should exist some kind of user object,
stored in the session, which holds the actual user data
or a dummy object, for a not logged in user.
This is the best approach I can think of. Therefor the right
place for instantiating this object is not a repository, neither
an action controller. It should be done somewhere, when the
user data is registered in the session, in my oppinion.
Would this be a good solution?
The user object stored in the session, if the user is not
logged in, should implement an interface to ensure a set of
available methods for fetching or storing data.
For now, as a temporary solution, I've written an if/else statement
inside the initializeAction method of the shopping cart controller,
which will load a user model coming from the user repository, which
will be assigned to the view. Inside the template I got another
if construct, which prints out the shopping cart items, if the
user object is set. If not, there is still a notice printed to
the user, to log in for using the shopping cart.
For now a logged out user can't add items to the cart.
Exists there some sort of best practice, handling such kind
of session storage? Does anybody have another idea?
Thanks for your support!
Thomas
Nathan Lenz schrieb:
> Thomas "Thasmo" Deinhamer wrote:
>
>> I thought of creating a kind of 'session object' put
>> onto the FeUser Model, which 'persists' all kind of
>> data not into the database, but rather into the session.
>>
>> After the user logs in, needed session data will be transformed
>> and/or cloned/copied into a FeUser object or will be persisted.
>>
>> I'm not sure if this is the best way. And if, I'm not quite sure
>> how to create such kind of session user object which will store
>> data in the session. (Maybe it's just a wrapper class over the
>> FeUserAuth class of TYPO3, I'm not sure.)
>
> I need to solve this same problem in the next few days.
>
> I was thinking about creating a session enabled repository for the
> object I need to persist into the session. Then the controller would
> just add,update,remove,etc... the object from the customized repository.
> The repository would handle the logic of deciding if it needs to
> persist the object to the database or the session. However, I'm not sure
> this makes sense. It doesn't matter to me where the data is persisted,
> just as long as it is available and I can access it.
>
> Another idea would be to add an "owner" property to the basket object.
> Then add a findByOwner() method to the basketRepository. I'm not sure if
> it's possible to make "owner" either a session id or a FeUser object.
>
> Your Basket controller would then do the logic:
>
> Basket->showAction() {
> owner = '';
> if (feUser exists) {
> owner = feUser
> } else if (sessionId exists) {
> owner = sessionID
> } else {
> no basket! why don't you create one.
> }
>
> view->assign('basket',$repos->findByOwner(owner));
> }
>
> In this case, baskets would be always persisted to the database.
>
> I'm not sure how I'm going to do it yet.
> --Nathan
More information about the TYPO3-project-typo3v4mvc
mailing list