Welcome Guest, Not a member yet? Register   Sign In
Redirect Not Working CI4
#12

(11-07-2019, 07:57 AM)Programaciones Web Wrote: Hello Guys. I started a new Project with CI4 to see the new features and I am struggling trying to redirect between pages.

It's really simple...

I have a Login Controller

PHP Code:
<?php namespace App\Controllers;

use App\Models\Login_Model;

class Login extends BaseController
{

    protected $login_model;

    public function __construct()
    {
        $this->login_model = new Login_Model();
    }

    public function index()
    {
        echo view('login/templates/header');
        echo view('login/dashboard_view');
        echo view('login/templates/footer');
    } 


And a Dashboard Controller


PHP Code:
<?php namespace App\Controllers;

class Dashboard extends BaseController
{

    public function index()
    {
        echo view('admin/templates/header');
        echo view('admin/dashboard_view');
        echo view('admin/templates/footer');
    }






I would like to control the User Sessions. If the user is not log in on the system... Redirect to Login View.
I would like to have this functionality in all my Controllers so I just add it to the BaseController.

PHP Code:
    protected $session;
    
    public function initController
(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);

        
        $this
->session = \Config\Services::session();

        // User Access Control
        if (!isset($_SESSION['user_logged_in'])) {
            return redirect()->to(base_url('/login') );
        }


    


I tried everthing with (/), adding to routes of course. With only redirect(); A lot of things... but seems like something changes in CI4 that I dont get it.


SYSTEMPATH/HTTP\Exceptions\HTTPException.php


Remove de "base_url", like this:

PHP Code:
return redirect()->to('/login'); 

That way works for me.
Reply


Messages In This Thread
Redirect Not Working CI4 - by Programaciones Web - 11-07-2019, 07:57 AM
RE: Redirect Not Working CI4 - by adelbak - 11-07-2019, 11:52 AM
RE: Redirect Not Working CI4 - by dave friend - 11-08-2019, 06:22 AM
RE: Redirect Not Working CI4 - by Chivinsdev - 11-11-2019, 09:21 AM
RE: Redirect Not Working CI4 - by Juan Fajardo - 06-02-2020, 10:49 AM
RE: Redirect Not Working CI4 - by kilishan - 11-11-2019, 09:58 AM
RE: Redirect Not Working CI4 - by InsiteFX - 11-12-2019, 04:07 AM
RE: Redirect Not Working CI4 - by Gary - 04-18-2020, 03:22 PM
RE: Redirect Not Working CI4 - by Gary - 04-18-2020, 07:16 PM
RE: Redirect Not Working CI4 - by Leo - 04-20-2020, 02:42 AM
RE: Redirect Not Working CI4 - by jim1001 - 05-21-2020, 04:26 AM
RE: Redirect Not Working CI4 - by dave friend - 05-21-2020, 01:02 PM
RE: Redirect Not Working CI4 - by Leo - 05-22-2020, 09:46 AM
RE: Redirect Not Working CI4 - by ivanfdr - 04-22-2020, 09:16 PM
RE: Redirect Not Working CI4 - by abeni_ab - 07-22-2020, 09:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB