Hi Gonzalo,
 
thank you for your advice. You are right in both. Nevertheless I confess
I am to lazy now to pipe my user session data through 3 models ( first
controller -> calls model -> calls next model) so I will be naughty and
do it with App::import('Model', 'CakeSession'); which works by the way. 

Thank you!

Anja

________________________________

Von: [email protected] [mailto:[EMAIL PROTECTED] Im
Auftrag von Gonzalo Servat
Gesendet: Donnerstag, 9. Oktober 2008 16:36
An: [email protected]
Betreff: Re: Access $this->Session from a model


On Thu, Oct 9, 2008 at 10:41 AM, Liebermann, Anja Carolin
<[EMAIL PROTECTED]> wrote:



        Hi all,
        
        Now that I have placed a function in my model rather than in my
        controller to avoid requestAction I have a new problem:
        
        The function gets data from my session.
        In the controller the following works:
               $user = $this->Session->read('User');
        
        When I place this code in my model method I get the error
message:
        Undefined variable: Session [APP\models\text.php, line 95]
        
        So I tried to avoid this by using the function like that:
               App::import('Model', 'Session');
               $Session = new Session()
               $user = $Session->read('User');
        
        This causes:
        Fatal error: Class 'Session' not found in...
        
        Questions: Is it possible to use Session data in my model? If
yes which
        syntax is correct?
        


Some people will probably jump in and say you shouldn't be reading
session data from the model (breaks MVC, etc). Maybe you can send it as
an argument to the model function?

If you insist, I think you want:

App::import('Model', 'CakeSession');
$session = new CakeSession();

.. but I'm not 100% sure.

- Gonzalo




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

Reply via email to