• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect on a Controller contruct

#1
Hi and sorry for my bad english, I have parent construct that check if the user is logged to let them see the page or redirect them to the login but since I updated to the alpha 3 it not works:

The route I try to go without login:
PHP Code:
$routes->add('{locale}/app/''Dashboard::index', ['namespace' => 'App\Controllers\Appmudet']); 

The Dashboard Controller that extends from the Appcontroller:
PHP Code:
<?php namespace App\Controllers\Appmudet;

class 
Dashboard extends Appcontroller{
 
   
    public 
function __construct() {
 
       parent::__construct();

 
   }

 
   public function index(){
 
       
        $this
->data['locale'] = $this->request->getLocale();              

        echo view
('app/common/header'$this->data);
 
       echo view('app/common/nav');
 
       echo view('app/common/advertising');
 
       echo view('app/common/advertising2');
 
       echo view('app/common/footer');
 
   }


The Appcontroller :
PHP Code:
<?php namespace App\Controllers\Appmudet;

use 
App\Controllers\Mudetcontroller;

class 
Appcontroller extends Mudetcontroller{
 
       public $ionAuth;
 
       public function __construct() {
 
           
            $this
->ionAuth = new \App\Libraries\IonAuth();
 
           
            if
(!$this->loggedIn()){
        
var_dump('asdasd');
 
               return redirect()->to('/es/login');
    }


It shows me the var_dump and then the redirect dosen't seems to work because shows me the app view not the login.
Both controlles are on the same folder: 'Controllers/Appmudet'
Reply

#2
PHP Code:
public function __construct() {
 
           
    $this
->ionAuth = new \App\Libraries\IonAuth();
 
           
    if
(!$this->loggedIn()){
        
var_dump('asdasd');
 
       return redirect()->to('/es/login');
    }


I don't think your "return" in a constructor will be effective.
Th only way I found, is to test "loggedIn" in each function.
Reply

#3
Redirecting from constructors is no longer possible in CI4. Use Controller filters instead.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.