I just store it in a session variable.  Any function that requires a
user to be logged in gets a line fo code like:

$this->Session->write('redirect', '/forums/index');
$this->checkSession();
$this->Session->delete('redirect');

This results in the user either getting redirected to the login page
via the checkSession() function if they're not logged in, or the
'redirect' session getting deleted if they're already logged in
(because if that's the case, we don't need to redirect them).  If the
user isn't logged in, they go to the login form, and enter their
username/password.

At that point (we've now moved to the login() function), if they
manage to log in correctly, I do something like this:

if(session_is_registered('redirect')) {
        $redirect = $this->Session->read('redirect');
        $this->Session->delete('redirect');
        $this->redirect($redirect);
}

... which sends them back to whichever page redirected them to the
login page.  Probably not the prettiest method, but it works.




On Jul 13, 1:39 pm, Vincent Fleuranceau <[EMAIL PROTECTED]>
wrote:
> Hi all,
>
> I'm new to CakePHP (and MVC in general). And so far I'm very happy
> wiht it.
>
> I've just followed the blog tutorial and I've combined it with the
> simple authentification example from the manual. It works well so far,
> but...
>
> I would like to know if there is a (simple) way to redirect the user
> to the requested page (instead of a default hard-coded URL). I hope
> you see what I mean.
>
> The original code reads:
>
> <?php
> class AppController extends Controller
> {
>     function checkSession()
>     {
>         // If the session info hasn't been set...
>         if (!$this->Session->check('User'))
>         {
>             // Force the user to login
>             $this->redirect('/users/login');
>             exit();
>         }
>     }}
>
> ?>
>
> Any idea how I can "store" the URL of the requested page and pass it
> to the redirect() method?
>
> Thanks in advance,
>
> -- Vincent


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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