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

Hi,
I have created a BaseController extending CI Controller :

Code:
<?php namespace App\Controllers;

class BaseController extends \CodeIgniter\Controller
{

    protected $env_data;
    protected $env_user;
    
    function __construct()
    {
        $this::init();
    }

    function init() {
        $this->env_data = ['init'=>'yes'];
        $this->env_user = [];

        if(empty($this->env_user)) {
            return redirect()->to('/login');
        }
    }


}
I then created controller Home2 :

Code:
<?php namespace App\Controllers;

class Home2 extends BaseController
{

    public function __construct()
    {
        parent::init();
    }

    public function index()
    {
        print_r($this->env_data);
        
        //return redirect()->to('/login');

        return view('welcome_message', $this->env_data);
    }
}
Calling Home2 displays array $this->env_data containing "init"=>'yes'. The redirection does not work.

Can someone confirm this is the expected result?

Why is redirection not working in BaseController?

Thanks in advance!
Reply


Messages In This Thread
Redirect - by oliver - 12-06-2018, 11:57 AM
RE: Redirect - by kilishan - 12-06-2018, 12:56 PM
RE: Redirect - by Inc33 - 04-25-2020, 01:35 AM
RE: Redirect - by oliver - 12-09-2018, 02:43 AM
RE: Redirect - by InsiteFX - 12-09-2018, 09:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB