-
eleumas Member
  
-
Posts: 66
Threads: 30
Joined: Jun 2017
Reputation:
1
08-17-2020, 04:25 AM
(This post was last modified: 08-17-2020, 07:30 AM by eleumas.)
Hi! I created a filter for auth but i would like apply this filter for all methods inside the controller.
This is my routes:
PHP Code: $routes->get('articles', 'Articles',['filter' => 'auth']); $routes->get('articles/(:any)', 'Articles',['filter' => 'auth']);
Is possible do it with a unique route? Someone can help me please? Thanks.
-
mlurie Member
  
-
Posts: 58
Threads: 16
Joined: Jul 2020
Reputation:
2
08-19-2020, 12:08 PM
(This post was last modified: 08-19-2020, 12:09 PM by mlurie.)
(08-17-2020, 04:25 AM)eleumas Wrote: Hi! I created a filter for auth but i would like apply this filter for all methods inside the controller.
This is my routes:
PHP Code: $routes->get('articles', 'Articles',['filter' => 'auth']); $routes->get('articles/(:any)', 'Articles',['filter' => 'auth']);
Is possible do it with a unique route? Someone can help me please? Thanks.
Check Grouping Routes in the CodeIgniter 4 documentation here: https://codeigniter.com/user_guide/incom...ing-routes. Apply your filter to the group.
-
eleumas Member
  
-
Posts: 66
Threads: 30
Joined: Jun 2017
Reputation:
1
08-20-2020, 02:18 AM
(This post was last modified: 08-20-2020, 03:23 AM by eleumas.)
(08-19-2020, 12:08 PM)mlurie Wrote: (08-17-2020, 04:25 AM)eleumas Wrote: Hi! I created a filter for auth but i would like apply this filter for all methods inside the controller.
This is my routes:
PHP Code: $routes->get('articles', 'Articles',['filter' => 'auth']); $routes->get('articles/(:any)', 'Articles',['filter' => 'auth']);
Is possible do it with a unique route? Someone can help me please? Thanks.
Check Grouping Routes in the CodeIgniter 4 documentation here: https://codeigniter.com/user_guide/incom...ing-routes. Apply your filter to the group.
I tried this code, but in order to work i have to add the name of group to url and this is a problem for me.
My url : articles/create
With filter group: mygroup/articles/create
PHP Code: $routes->group('mygroup', ['filter' => 'auth'], function($routes) { $routes->resource('dashboard'); $routes->resource('articles'); });
I would like apply the filter to controller and all methods if possible with a unique route.
Is it possible? Some code for example? Thanks.
-
mlurie Member
  
-
Posts: 58
Threads: 16
Joined: Jul 2020
Reputation:
2
(08-20-2020, 02:18 AM)eleumas Wrote: (08-19-2020, 12:08 PM)mlurie Wrote: (08-17-2020, 04:25 AM)eleumas Wrote: Hi! I created a filter for auth but i would like apply this filter for all methods inside the controller.
This is my routes:
PHP Code: $routes->get('articles', 'Articles',['filter' => 'auth']); $routes->get('articles/(:any)', 'Articles',['filter' => 'auth']);
Is possible do it with a unique route? Someone can help me please? Thanks.
Check Grouping Routes in the CodeIgniter 4 documentation here: https://codeigniter.com/user_guide/incom...ing-routes. Apply your filter to the group.
I tried this code, but in order to work i have to add the name of group to url and this is a problem for me.
My url : articles/create
With filter group: mygroup/articles/create
PHP Code: $routes->group('mygroup', ['filter' => 'auth'], function($routes) { $routes->resource('dashboard'); $routes->resource('articles'); });
I would like apply the filter to controller and all methods if possible with a unique route.
Is it possible? Some code for example? Thanks. 
Auto-routing only works if you include the class name as part of the path. If you don't want the class name (group name) in the URL, you will need to manually specify the Controller\method like this:
PHP Code: $routes->group('mygroup', ['filter' => 'auth'], function($routes) { $routes->add('dashboard', 'Mygroup::dashboard'); $routes->add('articles', 'Mygroup::articles'); }
|