![]() |
How to get method name in view ? - 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: How to get method name in view ? (/showthread.php?tid=88396) |
How to get method name in view ? - sknair143 - 09-04-2023 Hello, I want to get the method name in the view to display a CSS class based on that. I have a method like "employees/documents" (Employees - Controller, Documents - method) In view how i can get the method name "documents" ?, is there any built-in function from codeigniter ? Right now i created custom_helper.php : PHP Code: <?php and in view Code: <?php echo (get_url() == 'documents') ? 'active' : ''; ?> This works !, but if any parameters come witht this url, i need to edit again. is there any alternative way which you can suggest ? RE: How to get method name in view ? - kenjis - 09-04-2023 You can get it from the router. PHP Code: \Config\Services::router()->methodName() RE: How to get method name in view ? - sknair143 - 09-04-2023 (09-04-2023, 01:09 AM)kenjis Wrote: You can get it from the router. Can i call this directly from view or i have to add in custom_helper code ? RE: How to get method name in view ? - kenjis - 09-04-2023 I recommend you create a custom helper. Then, if the behavior of the router changes, you will need to update the helper code only. RE: How to get method name in view ? - sknair143 - 09-04-2023 (09-04-2023, 01:25 AM)kenjis Wrote: I recommend you create a custom helper. Okay, thanks. RE: How to get method name in view ? - InsiteFX - 09-04-2023 Here's a quick helper to get you going. PHP Code: <?php |