Welcome Guest, Not a member yet? Register   Sign In
Issue with the controller arguement
#5

(This post was last modified: 07-11-2018, 05:54 AM by scalla.)

the redirect does not work for the filter.
below is my sample code for staff authentication,if i use raw head location which i commented below, it works well.
in my observation, seems there is an issue with the sent out header.
PHP Code:
<?php namespace App\Filters;

use 
Config\Services;
use 
CodeIgniter\Events\Events;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;
class 
StaffAuth implements FilterInterface
{
    public function 
before(RequestInterface $request)
    {
        
$auth Services::Auth('Staff');

        if (
$request->uri->getSegment(3) != 'login')
        {
            if (!
$auth->isLoggedIn())
            {
         
     if ($request->isAJAX())
         
     {
         
         $this->jsonresponse = [
                     
  'status'      => 'error',
                     
  'redirectUrl' => route_to('StaffLogin'),
                    ];
                    return 
Services::response()->setJson($this->jsonresponse);
         
     }
         
     //return redirect(route_to('StaffLogin').'?redirect_to='.urlencode($request->detectPath('REQUEST_URI')));
         
     //header('Location: ' . site_url(route_to('StaffLogin')), TRUE, 302);
                //exit;
         
     return redirect()->route('StaffLogin');
         
  }
         
  Events::trigger('Auth.loggedin', []);
        }
    }

 
 //--------------------------------------------------------------------

    
public function after(RequestInterface $requestResponseInterface $response)
    {
        
// Do something here
    
}

Reply


Messages In This Thread
Issue with the controller arguement - by scalla - 07-10-2018, 05:42 PM
RE: Issue with the controller arguement - by scalla - 07-11-2018, 05:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB