Welcome Guest, Not a member yet? Register   Sign In
Route wont work
#1

(This post was last modified: 01-02-2025, 02:47 AM by 4usol.)

Hi,

i try to run a simple redirection but i failed.

Code:
redirect('access_denied/index/myval');

it should rout to the controller in my base-folder "access_denied" to the funtion "index" and the values for the index-function with "myval".

routes.php
Code:
$routes->get('access_denied', '\App\Controllers\Access_denied::index'); //no result ->The route for "access_denied/index/myval" cannot be found
$routes->get('access_denied/(:any)', '\App\Controllers\Access_denied::index'); ->The route for "access_denied/index/myval" cannot be found

What i'm doing wrong?

Update
The Route: $routes->get('accessdenied/(:any)', 'Access_denied::index/$1');
dont work like it should be, i will always redirect to the shield/login page - maybe there is a problem with the settings about the shield-routes?

in the Filter Config is this:
Code:
public array $globals = [
        'before' => [
            // ...
            'session' => ['except' => ['login*', 'register', 'auth/a/*', 'logout']],
        ],
        // ...
    ];

if i comment this line out, the route seems to work. Now i ask myselt how i can change the filter.

I want that all pages avivable outside a subfolder in the controllers named "myadminarea" this folder should be only accessable for loggedin users.
Reply
#2

(This post was last modified: 01-02-2025, 02:46 AM by captain-sensible.)

take out
Code:
\App\Controllers\
so its :


$routes->get('access_denied', 'Access_denied::index');

and see if it helps, i think underscore is an allowed character although i would have written it camel case accessDenied
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#3

(This post was last modified: 01-02-2025, 02:48 AM by 4usol.)

thanks i've update my code above, the problems seems to comes from the filter-config. May you have a look at this?
Reply
#4

Adding access_denied* to the list should work
PHP Code:
public array $globals = [
        'before' => [
            // ...
            'session' => ['except' => ['login*''register''auth/a/*''logout''access_denied*']],
        ],
        // ...
    ]; 
Reply
#5

(This post was last modified: 01-02-2025, 08:39 AM by 4usol.)

Ok, but is there still a way to change the way it works?

At the moment all pages will "protected" i've not defined in the "except" Array.

Much easier for me it will be if i
- define a subfolder to protect - with all possible controllernames etc as a kind of wildcard "myfolder/*"
- all other pages wont protected and rund only like defined in the routes

Update
I decide to use the filter function not and add a own function to every page.

Now i need a bit help to create a dynamic routes for the logged-in area. I cannot define all possible routes, so i need to create a flexible route how works for all  possible url-combinations 

The idear will be something like that:
$routes->get('myfolder/(:alphanum)/(:alphanum)/(:alphanum)/(:alphanum)', '\App\Controllers\Myfolder\$1\$2$\$3\$4');

But this failed, is it possible to do something like that?
Reply
#6

In that case, remove the entire session key and go down to the $filters property:

PHP Code:
public array $filters = [
    'session' => ['before' => ['myfolder/*']],
]; 
Reply
#7

Great, but now i've decide to use the filter function not and add a own function to every page.

Now i need a bit help to create a dynamic routes for the logged-in area. I cannot define all possible routes, so i need to create a flexible route how works for all possible url-combinations

The idear will be something like that:
$routes->get('myfolder/(:alphanum)/(:alphanum)/(:alphanum)/(:alphanum)', '\App\Controllers\Myfolder\$1\$2$\$3\$4');

But this failed, is it possible to do something like that?
Reply
#8

Not a good idea. Just go with auto routing improved.
Reply
#9

(This post was last modified: 01-02-2025, 10:30 AM by 4usol.)

After enable the autoroute, my shield login wont work corretly.

For example the routes for "auth/a/handle" etc. runs into a 404-error.

May i have to go back to the beginning to create a kind of dynamically route...

...or is it possible to cretae the entries in the route.php dynmically after login by values from database (i have diffrent modules (with diffrent url-syntax) wich users can en/disable, for that i looking for a easy but flexible way)
Reply
#10

Do you still have
PHP Code:
service('auth')->routes($routes); 
in your app/Config/Routes.php file? It should work just fine.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB