Thursday, January 28, 2010

Re: now Using Session on my model

A callback in the controller avoid a broken the MVC pattern.

On 01/28/2010 02:20 PM, Jamie wrote:
> Well, it's certainly better than importing the component...
>
> If you want to be strict about it (and I'm not exactly sure how the
> method I suggests falls outside of the MVC pattern, since session info
> is just data, just like model data), then just make a model:
>
> class UserSession extends AppModel {
> public $name = 'UserSession';
> public $useTable = false;
>
> public $session = null;
>
> function __construct($id = false, $table = null, $ds = null) {
> parent::__construct($id, $table, $ds);
> App::import('Core', 'CakeSession');
> $this->session = new CakeSession();
> }
>
> }
>
> Then you can just use the MySession class in your other models:
>
> ClassRegistry::init('MySession')->session->read('Data');
>
> Obviously not the most elegant solution, but hey, it uses a model. ;)
>
> Totally untested but that wraps the session data inside a model.
> On Jan 27, 11:07 pm, the_guru<l.rajibah...@gmail.com> wrote:
>
>> @Jamie,
>>
>> Its not wrong , its just not best practice and fall out of palce for
>> MVC design pattern i guess.
>>
>> On Jan 26, 3:45 am, Jamie<jamie....@gmail.com> wrote:
>>
>>
>>> You don't need to import a component, especially since components are
>>> for controllers. You can just do this in your Cartmodel:
>>>
>>
>>> public $session= null;
>>>
>>
>>> function __construct($id = false, $table = null, $ds = null) {
>>> parent::__construct($id, $table, $ds);
>>> App::import('Core', 'CakeSession');
>>> $this->session= new CakeSession();
>>>
>>
>>> }
>>>
>>
>>> All the SessionComponent does is provide a controller-level wrapper
>>> for the CakeSession class. I don't see anything wrong with importing
>>> CakeSession itself right into yourmodel.
>>>
>>
>>> You can still do all of the regularsessionfunctions:
>>>
>>
>>> $this->session->read
>>> $this->session->delete
>>> $this->session->write
>>>
>>
>>> etc.
>>>
>>
>>> - Jamie
>>>
>>
>>> On Jan 20, 12:40 am, the_guru<l.rajibah...@gmail.com> wrote:
>>>
>>
>>>> Hello Every body i am now usingSessioncomponent on my Cartmodel
>>>>
>>
>>>> I have CartModelwhich does not extends from AppModel
>>>>
>>
>>>> Now here is the code that i am using to accessSessionproperties
>>>>
>>
>>>> class Cart
>>>> {
>>>> public $Session= null;
>>>>
>>
>>>> public function __construct(){
>>>> App::import('Component', 'SessionComponent');
>>>> $this->Session= new SessionComponent;
>>>> }
>>>>
>>
>>>> public function add($id){
>>>>
>>
>>>> }
>>>>
>>
>>>> public function remove($id)
>>>> {
>>>>
>>
>>>> }
>>>>
>>
>>>> }
>>>>
>>
>>>> ?>
>>>>
>>
>>
> Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: