Accessing Session Variables in Model

Tuesday, April 17, 2012 1 Comments

This early morning (right now based on Indonesia time GMT+7, it's 8.18 AM), I've been preparing my to-do-list to be done later in my office associated with my countdown-project. It's all about to log every query executed by user action (create/ add, edit and delete) to database by using cakePHP. I've been spending a lot of time on searching the snippet or at least what-kind-of-function-I-must-used-to, and not find my need yet.

Yesterday, since I've found the how-to, based on the link I've found on Stackoverflow and edited it to be like what I want (read : need), I still have to do a lil bit experiment.

It's like this title's post. Accessing session variables in Model. Is that possible? Come on,, it's just PHP. Anything possible.

So many ways to get the session variables when we are in Model. For example, importing the Session Component (or even the CakeSession core) or simply call $_SESSION. That's it. But, remember, we must know about 'BIG BUT' below..
Of course we could access session in Model BUT of course it's also breaking the MVC design pattern itself.

The solution

Callbacks. The controllers and model callback is created to avoid a broken the MVC pattern. So HOW? Refer to this link, I got what I need :) Aaah.. Stackoverflow is such a savior :D

Disclaimer

I'm not sure if my explanation is clear enough. Follow the reference-links below if you wanna get you're own understanding :D

References :

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Do you think I forgot to change this text? No, dude. I did it on purpose ahahahay..

1 comments:

Write comments