Welcome Guest, Not a member yet? Register   Sign In
redirect() in base controller
#6

Somebody can help ??? What I'm I doing wrong ??
I'm still on my way to achieve my function checkRole working correctly.
Kenjis said it must return an redirectResponse object.
So I've changed my library.
I replace $response = \config\Services::response(); by $redirectResponse = \config\Services::redirectresponse();

Here is my code :

PHP Code:
<?php

namespace App\Libraries;

class 
GAuthLib {

    public function checkAccess(array $roles) {
        $config config('thisApp');
        $redirectResponse = \config\Services::redirectresponse();

        // No role : redirection
        if (!isset($_SESSION[$config->appName]['user']['role'])) {
            return $redirectResponse->to(site_url('auth/index'));
            die("<p>No role defined.</p>");
        }
        // Got role. Check if controller accept this role.
        else {
            if (in_array($_SESSION[$config->appName]['user']['role'], $roles)) {
                return TRUE;
            } else {
                return $redirectResponse->to(site_url('home/index'));
                die("<p>No right ! Can't access.</p>");
            }
        }
    }

    

But redirection doesn't work.

$redirectResponse->to() return a redirectResponse object (I think !!).
Here is a dump on it (just a part) :
PHP Code:
C:\wamp64\www\g\app\Libraries\GAuthLib.php:15:
object(CodeIgniter\HTTP\RedirectResponse)[89]
  protected 'protocolVersion' => string '1.1' (length=3)
  protected 'validProtocolVersions' => 
    array (size=3)
      0 => string '1.0' (length=3)
      1 => string '1.1' (length=3)
      2 => string '2.0' (length=3)
  protected 'body' => null
  
protected 'headers' => 
    array (size=3)
      'Cache-control' => 
        object(CodeIgniter\HTTP\Header)[90]
          protected 'name' => string 'Cache-control' (length=13)
          protected 'value' => 
            array (size=3)
              ...
      'Content-Type' => 
        object(CodeIgniter\HTTP\Header)[92]
          protected 'name' => string 'Content-Type' (length=12)
          protected 'value' => string 'text/html; charset=UTF-8' (length=24)
      'Location' => 
        object(CodeIgniter\HTTP\Header)[93]
          protected 'name' => string 'Location' (length=8)
          protected 'value' => string 'http://localhost/g/public/index.php/home/index' (length=46

So if someone can explain me how to achieve this function working correctly...
Thanks
Reply


Messages In This Thread
redirect() in base controller - by sTis - 03-16-2023, 02:18 AM
RE: redirect() in base controller - by kenjis - 03-16-2023, 04:02 AM
RE: redirect() in base controller - by sTis - 03-16-2023, 06:00 AM
RE: redirect() in base controller - by kenjis - 03-16-2023, 05:08 PM
RE: redirect() in base controller - by sTis - 03-17-2023, 03:02 AM
RE: redirect() in base controller - by sTis - 03-19-2023, 09:55 AM
RE: redirect() in base controller - by InsiteFX - 03-19-2023, 11:26 PM
RE: redirect() in base controller - by iRedds - 03-20-2023, 03:20 AM
RE: redirect() in base controller - by sTis - 03-24-2023, 05:50 AM
RE: redirect() in base controller - by Muzikant - 04-19-2023, 02:51 AM
RE: redirect() in base controller - by kenjis - 04-19-2023, 03:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB