![]() |
I have to run some condition in every controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: I have to run some condition in every controller (/showthread.php?tid=79506) |
I have to run some condition in every controller - mostafiz80 - 06-25-2021 I have to run some condition in every controller. i have posted my code below. now i use __construct how can i make it more nicely. now the full code i have to put in every controller but i want to make it other easier way. Please help i am new in codeigniter but nowdays i loving it. i saw codeigniter before 10 years ago but i ignore it because thats time i was new in php. PHP Code: protected $request; RE: I have to run some condition in every controller - John_Betong - 06-25-2021 Hi @mostafiz80 and a warm welcome to the forums. I have similar problems which I resolve by ensuring all Controllers extend BaseController: PHP Code: class C_home extends BaseController In BaseController use the following method: file: ./app/Classes/BaseController PHP Code: public function initController To test try this in your common View/vheader menu or common View/vFooter: PHP Code: echo '<h6>' .$test_001 .'</h6>'; RE: I have to run some condition in every controller - paliz - 06-26-2021 initController.its better _constructor I used tooo RE: I have to run some condition in every controller - MGatner - 06-27-2021 I would recommend you look into Filters: https://codeigniter.com/user_guide/incoming/filters.html RE: I have to run some condition in every controller - mostafiz80 - 06-28-2021 Thanks all of you guys for help. i have done using library. i like to use library. Now i am stuck in Mysql transaction. The mysql LOCK IN SHARE MODE how will work this query if i use codeigniter transaction. i have to do some transaction on my application. RE: I have to run some condition in every controller - InsiteFX - 07-05-2021 Transaction lock and unlock the tables , what you have to watch for is dead locks. To fix dead locks use small optimized queries. RE: I have to run some condition in every controller - paliz - 07-05-2021 Use filter , https://codeigniter.com/user_guide/incoming/filters.html?highlight=filter RE: I have to run some condition in every controller - superior - 07-09-2021 Like @MGatner said, i would recommend using CodeIgniter 4 Filter as well. |