Welcome Guest, Not a member yet? Register   Sign In
Redirect issue
#1

(This post was last modified: 06-12-2023, 02:09 AM by Zeff.)

Dear all,

I have a strange issue when I use the return redirect()->to() function:
In my controller; I have this method:
PHP Code:
private function _check_login()
{
    $auth service('simplecas');
    $this->user $auth->logged_in_user(); 
    $this->data['user'] = $this->user;

    if(!isset($this->user) || is_null($this->user))
    {
        //return redirect()->to('no_valid_userid');
        return redirect()->route('no_valid_userid');
    }
    // Check if user id is in a given array of allowed uids
    elseif(is_array($this->user) &&  !in_array($this->user['uid'], $this->allowed_uids))
    {
        //die('Not allowed');
        //return redirect()->to('/issues/not_allowed');
        return redirect()->route('not_allowed');
    }
    else
    {
        $this->data['user'] = $this->user;
    }

In my routes config file, I added:
PHP Code:
$routes->add('not_allowed''Issues::not_allowed');
$routes->add('no_valid_userid''Issues::no_valid_userid'); 

Neither way of redirection (via 'route' or 'to' works), the code just continues no mather if the user is logged in or not.
If I uncomment the die('Not allowed') line, it works (scrips stops).
Can anyone explain this behaviour? What am I doing wrong?

Many thanks in advance!
Reply
#2

You need to return the Response object from your controller.
You return it from the _check_login() method, but do you return it from the public method?
Reply
#3

(06-12-2023, 03:59 AM)kenjis Wrote: You need to return the Response object from your controller.
You return it from the _check_login() method, but do you return it from the public method?

Hi kenjis, it's obvious indeed but I missed that one. Many thanks!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB