I hear cricket's point of view, but in a fairly complex model function you 
might need to read from or write to the session several times and in a 
dependent way (based on what happens inside the model function) so you don't 
necessarily know what variables to send in (unless you're a belt and braces 
fan). I often find myself returning an array from the model so that the 
controller function can parse it and do things like redirect to the right 
place, work out if/what error occurred, set the flash message etc. The model 
could do some of that stuff (I'm not suggesting a redirect there of course).

Sometimes a controller function has to just let go of the situation and lose 
contact with the data while the model function does its stuff and it doesn't 
really know what's coming back, how to handle it or what to do next. That adds 
unnecessary overhead to the controller function that could be relieved somewhat 
by the model.

I don't see a huge problem with working that way.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
(t) +44 (0) 208 123 3822
(m) +44 (0) 7973 481949
Skype: jeremy_burns
http://www.classoutfit.com

On 28 Mar 2011, at 11:44, euromark wrote:

> it is a very neat thing to have access to the session inside the model
> check out Miles' approach
> he uses it in his forum plugin:
> http://milesj.me/resources/script/forum-plugin
> 
> On 28 Mrz., 08:00, cricket <zijn.digi...@gmail.com> wrote:
>> On Mon, Mar 28, 2011 at 12:54 AM, Krissy Masters
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> <naked.cake.ba...@gmail.com> wrote:
>>> Why is the Session data not available in the Model?
>>> Why is it breaking MVC?
>>>  I do not understand since all data comes from the database basically and if
>>> I am saving my session data to the db why would grabbing that data in the
>>> model be bad?
>> 
>>> I found Miles J snip for the app_model which I plan to use to get session
>>> data since it makes more sense to grab user.id from the session directly in
>>> the model rather than grab it in controller only to pass it to the model in
>>> the controller function to be used in the model function.
>> 
>>> public function __construct($id = false, $table = null, $ds = null) {
>>>        parent::__construct($id, $table, $ds);
>> 
>>>        $this->Session = new CakeSession();
>>> }
>> 
>>> Any insight on how this breaks MVC?
>> 
>> The request shoud be irrelevant to the model. That's for the
>> controller to deal with. If you have model methods which are dependent
>> on request data (which, essentially, is what session vars are) just
>> pass them to your model methods from the controller.
>> 
>> If you've got a lot of params to send, consider using an associative
>> array, the way most everything else in Cake works.
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to