Welcome Guest, Not a member yet? Register   Sign In
Routes and Placeholders
#1

(This post was last modified: 05-21-2021, 04:23 AM by p.mancini.)

In Config\Routes.php I created this roule
PHP Code:
$routes->group(SEGMENTURL_ADMIN, ['filter' => 'admin_role:superadmin,admin'], function($routes) {
    
$routes->get('(:segment)''$1_admin');
}); 
but the script return a 404 error (\App\Controllers$1_admin::index).

If I add any char before the placeholder, example
PHP Code:
$routes->group(SEGMENTURL_ADMIN, ['filter' => 'admin_role:superadmin,admin'], function($routes) {
    
$routes->get('(:segment)''_$1_admin');
}); 
the script run ok!!!


No problem without a group routes, for example 
PHP Code:
$routes->get('{locale}/(:segment)''$1_frontend'); 


is there a bug or am I wrong something?

Thanks!
Reply
#2

There is no controller/method in the filter read this.

PHP Code:
// No controller in the filter.
$routes->group(SEGMENTURL_ADMIN, ['filter' => 'filter_name'], function($routes) {



CodeIgniter 4 User Guide - Configuring Filters
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 05-21-2021, 05:55 AM by p.mancini.)

No, I also set Config/Filters.php 
PHP Code:
    public $aliases = [
        
'csrf'        => CSRF::class,
        
'toolbar'    => DebugToolbar::class,
        
'honeypot'    => Honeypot::class,

        
'admin_login'        => \Myth\Auth\Filters\LoginFilter::class,
        
'admin_role'        => \Myth\Auth\Filters\RoleFilter::class,
        
'admin_permission'    => \Myth\Auth\Filters\PermissionFilter::class,
    ]; 
Reply
#4

(This post was last modified: 05-21-2021, 12:37 PM by InsiteFX.)

Restricting Route Groups
In the same way, entire groups of routes can be restricted within the 

PHP Code:
$routes->group('admin', ['filter' => 'role:admin,superadmin'], function($routes) {
    ...
}); 

I'm not sure were you are getting your values from but that's how Myth/Auth shows it.

And the filters are these:

PHP Code:
'login'      => \Myth\Auth\Filters\LoginFilter::class,
'role'       => \Myth\Auth\Filters\RoleFilter::class,
'permission' => \Myth\Auth\Filters\PermissionFilter::class, 

There has been a few updates to Myth/Auth maybe download it again.

UPDATE: I just checked and Myth/Auth was updated again 7 hours ago.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

Thanks a lot for the answers InsiteFX.

The problem is not with the filters.

In fact, the problem remains even if I remove filters and change the routing code to
PHP Code:
$routes->group(SEGMENTURL_ADMIN, function($routes) {
    
$routes->get('([\w_-]+)''$1_admin');


Result: 404 error "Controller or its method is not found: \App\Controllers$1_admin::index".

The placeholder appears to have problems if placed at the beginning.

If I change the rule to
PHP Code:
$routes->group(SEGMENTURL_ADMIN, function($routes) {
    
$routes->get('([\w_-]+)''admin_$1');

or
PHP Code:
$routes->group(SEGMENTURL_ADMIN, function($routes) {
    
$routes->get('([\w_-]+)''xyz_$1');

then Codeigniter works correctly!
Reply
#6

CodeIgniter is probably checking the first character to see if its a dollar sign for matching parameters.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB