On 13 juil, 23:51, kionae <[EMAIL PROTECTED]> wrote:

> 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');
>

Thank you Kionae for your answer, it helped me a lot figure out how to
modify the checkSession() function,
(so that I don't end up with duplicate code everywhere).

For those who are interested, here is the modified version:
(the code goes in app/app_controller.php, see the original tutorial
for details)

<?php
class AppController extends Controller
{
    function checkSession()
    {
        // If the session info hasn't been set...
        if (!$this->Session->check('User'))
        {
            // Save the requested URL for the final redirection
            $this->Session->write('redirect', $this->params['url']
['url']);

            // Force the user to login
            $this->redirect('/users/login');
            exit();
        }
    }
}
?>

(NOTA: it took me some time to realize that params['url'] is an ARRAY
and the actual URL is stored in params['url']['url'])


And in users_controller.php I've changed:

    $this->redirect('/posts');

(NOTA : the original code mentions $this->redirect('/clients); if I
remember well but you have to replace 'clients' by 'posts'
if you want to use the auth tutorial combined with the blog tutorial)

into:

    $newUrl = $this->Session->read('redirect');
    $this->Session->delete('redirect');
    $this->redirect($newUrl);

Of course, feel free to correct me if this is a bad way of doing it.

Cheers,

-- 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