CodeIgniter Forums
Filter's dont work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Filter's dont work (/showthread.php?tid=78095)

Pages: 1 2


RE: Filter's dont work - pippuccio76 - 12-05-2020

so it's no possible write only one row for every controller's method  ? In ci3 i insert the control in constructor ( control if isset a session variable) but seem not working in ci4

OFFTOPIC:

Matleyx ti ho inviato dei privati ma forse non li hai letti 


RE: Filter's dont work - tgix - 12-05-2020

(12-05-2020, 01:48 AM)pippuccio76 Wrote: so it's no possible write only one row for every controller's method  ? In ci3 i insert the control in constructor ( control if isset a session variable) but seem not working in ci4

As I understand it you are asking two questions:
1) one row for each controller method?
Yes, you can do:
PHP Code:
$routes->post('example''Controller\example'); 

2) control in constructor in CI4
I understand the pain - in CI3 I used the constructor to check for access and bailed out if no access.
For CI4 you should look into Controller before Filters instead - https://codeigniter4.github.io/userguide/incoming/filters.html#before-filters
Also, in CI4, the constructor of a controller is replaced with initController - https://codeigniter4.github.io/userguide/extending/basecontroller.html


RE: Filter's dont work - pippuccio76 - 12-06-2020

(12-05-2020, 02:01 AM)tgix Wrote:
(12-05-2020, 01:48 AM)pippuccio76 Wrote: so it's no possible write only one row for every controller's method  ? In ci3 i insert the control in constructor ( control if isset a session variable) but seem not working in ci4

As I understand it you are asking two questions:
1) one row for each controller method?
Yes, you can do:
PHP Code:
$routes->post('example''Controller\example'); 

2) control in constructor in CI4
I understand the pain - in CI3 I used the constructor to check for access and bailed out if no access.
For CI4 you should look into Controller before Filters instead - https://codeigniter4.github.io/userguide/incoming/filters.html#before-filters
Also, in CI4, the constructor of a controller is replaced with initController - https://codeigniter4.github.io/userguide/extending/basecontroller.html

The first and second are for the same purpose , redirect if the user/admin isn't logged ...

The answer is :
Can i redirect every method of controller if the user/admin  isn't logged write only one row f.e 
$routes->add('Controller_name','filter' => 'adminFiltersNoAuth']);
?


RE: Filter's dont work - tgix - 12-06-2020

(12-06-2020, 02:27 AM)pippuccio76 Wrote: The answer is : 
Can i redirect every method of controller if the user/admin  isn't logged write only one row f.e 
$routes->add('Controller_name','filter' => 'adminFiltersNoAuth']);
?
My guess is that you need to use $routes-group() for that.


RE: Filter's dont work - InsiteFX - 12-06-2020

Correct if you apply a Filter to a group from what I have done it doe's apply to all routes under that group.


RE: Filter's dont work - pippuccio76 - 12-06-2020

(12-06-2020, 07:40 AM)InsiteFX Wrote: Correct if you apply a Filter to a group from what I have done it doe's apply to all routes under that group.
My english is poor i understand  Big Grin , therefore in ci 3 with few row inside the construct :

if(!isset($_SESSION['is_admin'])){
redirect('/admin/login', 'refresh');
}


now i must write a row for every controller's method....


RE: Filter's dont work - SkyRipper - 12-07-2020

(12-06-2020, 10:11 AM)pippuccio76 Wrote:
(12-06-2020, 07:40 AM)InsiteFX Wrote: Correct if you apply a Filter to a group from what I have done it doe's apply to all routes under that group.
My english is poor i understand  Big Grin , therefore in ci 3 with few row inside the construct :

if(!isset($_SESSION['is_admin'])){
redirect('/admin/login', 'refresh');
}


now i must write a row for every controller's method....

use controller filter for that, no need to duplicate the check on each methods

documentation link = https://codeigniter.com/user_guide/incoming/filters.html?highlight=filter

watch for tutorial here = https://www.youtube.com/watch?v=5DLgPldkQxc&t=774s