How to save the session in the view. In tutorial it is mentioned that
we should not use the write method in the view. Then what is the
alternative method to save the sessions in the view of cake php.

On Oct 14, 9:20 pm, brian <bally.z...@gmail.com> wrote:
> On Wed, Oct 14, 2009 at 4:00 AM, Prof. No Time
>
> <libertylivingst...@gmail.com> wrote:
>
> > Thanks Brian,
>
> > I am using the AUTH component. I want to access Auth.user() in the
> > view and I think the only way I can do that is if I can get the
> > controller in the view so I can say this->controller->Auth->user(). I
> > guess this is the wrongest way to go right? But I am new and just
> > floating around trying to find my feet. Please don't be irritated with
> > my blunders, help me.
>
> In a view, use $session->read('Auth.User.some_field'), eg.
> $session->read('Auth.User.last_name'). Put this in one of your views:
>
> debug($session->read('Auth.User'))
>
> If Auth's $userModel is something other than 'User' replace with that
> model name instead.
>
> > Also, when I use the auth component, I'd like to know the following:
> > 1. How and When do I know that the Auth component has successfully (or
> > otherwise) authenticated the user? Is there something like if ($this-
> >>Auth->authSuccess){}?
>
> If you are not redirected properly and you see an error msg then login
> was unsuccessful.
>
> > 2. How can I perform further actions after a successful auth like,
> > save the login time, check for file permissions and load them, notify
> > other people that someone just logged in?
>
> In AppController::beforeFilter()
>
> $this->Auth->loginRedirect = array(
>         'controller' => 'public_static',
>         'action' => 'display',
>         'home'
> );
> $this->Auth->autoRedirect = false;
>
> The last line tells Auth not to redirect the user immediately. Add a
> login() method to UsersController:
>
> public function login()
> {
>         if (!empty($this->data) && $user = $this->Auth->user())
>         {
>                 $last_login = date('Y-m-d H:i:s');
>                 $this->User->id = $user['User']['id'];
>                 $this->User->saveField('last_login', $last_login);
>                 $this->Session->write('Auth.User.last_login', $last_login);
>                 $this->redirect($this->Auth->loginRedirect);
>         }
>
> }
> > I'm grateful for your help. God bless you!
>
> > On Oct 13, 6:11 pm, brian <bally.z...@gmail.com> wrote:
> >> On Tue, Oct 13, 2009 at 12:37 PM, Prof. No Time
>
> >> <libertylivingst...@gmail.com> wrote:
>
> >> > Hello People, thanks so much for your attempts at my bake problem.
> >> > Obviously no one was close at all to the answer but I figured out
> >> > myself how to bake and I have baked successfully quite a number of
> >> > times now. I am new to this cake thing and I hope you guys can help me
> >> > sail through. I love Qcubed because they always answer when I cry, I
> >> > hope cake won't be any different.
>
> >> > Now to my Question, please, how do I access the CONTROLLER and SESSION
> >> > in a VIEW? Is it possible? If yes HOW, if no ALTERNATIVE.
>
> >> In the view, use $session['whatever']. Add debug($session) to see what
> >> it looks like.
>
> >> As for accessing the controller, it's not really set up for that and
> >> you probably don't need to. What are you trying to do?

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to