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