• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect

#3
Hi,
Thanks for your answer, Kilishan.
I've read the guide concerning filters : seems to be a real improvement in CI4!
But I still can't get my redirect working.
I created application/Filters/AuthFilter.php :

Code:
<?php namespace App\Filters;

use Config\Services;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class AuthFilter implements FilterInterface
{

 public function before(RequestInterface $request)
 {
    echo "filtered";
   return redirect('login');
 }

 public function after(RequestInterface $request, ResponseInterface $response)
 {

 }
}


Then I changed Config/Filters:

Code:
<?php namespace Config;

use CodeIgniter\Config\BaseConfig;

class Filters extends BaseConfig
{
    public $aliases = [
        'csrf'     => \App\Filters\CSRF::class,
        'toolbar'  => \App\Filters\DebugToolbar::class,
        'honeypot' => \App\Filters\Honeypot::class,
        'authfilter' => \App\Filters\AuthFilter::class
    ];

    public $globals = [
        'before' => [
            'authfilter' => ['except'=>['login']]
        ],
        'after'  => [
            'toolbar'
        ],
    ];

    public $methods = [];

    public $filters = [];
}
Which works fine when using login controller directly : the page displays without displaying "filtered".
But when I try to reach Home2::index, only "filtered" is displayed, no redirection takes place :

Code:
<?php namespace App\Controllers;

class Home2 extends BaseController
{

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

    public function index()
    {

        return view('welcome_message', $this->env_data);
    }

}
Just in case, here is my BaseController
Code:
<?php namespace App\Controllers;

class BaseController extends \CodeIgniter\Controller
{

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

    function init() {
        helper('html', 'url');
        $this->env_data = ['init'=>'yes'];
        $this->env_user = [];
    }

}
Thanks for your help.
Reply


Messages In This Thread
Redirect - by oliver - 12-06-2018, 12:57 PM
RE: Redirect - by kilishan - 12-06-2018, 01:56 PM
RE: Redirect - by oliver - 12-09-2018, 03:43 AM
RE: Redirect - by InsiteFX - 12-09-2018, 10:57 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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