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

Hello.
There is my custom filter:
PHP Code:
<?php

namespace App\Filters;

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

class 
Authorization implements FilterInterface
{
    public function before(RequestInterface $request)
    {
        $auth service('auth');
        if (! $auth->isAuth())
            return redirect()->route('403');
    }
    
    
public function after(RequestInterface $requestResponseInterface $response)
    {
        
    
}


It's work fine: if user is not authorized at some page he will be redirected to page 403.

Question: is there any way to do the same without physically redirect?

For example:
PHP Code:
<?php

namespace App\Filters;

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

class 
Authorization implements FilterInterface
{
    public function before(RequestInterface $request)
    {
        $error_403_Controller = new \App\Controllers\Error403Controller();
        return $error_403_Controller->index();
        exit;
    }
    
    
public function after(RequestInterface $requestResponseInterface $response)
    {
        
    
}

It's not working fine.

i need something like this:
redirect()->controller('403');

or this:
return loadController('403');
Reply




Theme © iAndrew 2016 - Forum software by © MyBB