Welcome Guest, Not a member yet? Register   Sign In
How to get method name in view ?
#1

(This post was last modified: 09-04-2023, 12:46 AM by sknair143.)

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

if (!function_exists("get_url")) {

    function get_url(): string
    
{

        $url $_SERVER['REQUEST_URI'];

        $exp explode("/"$url);


        return $exp[3];


    }







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 ?
Reply


Messages In This Thread
How to get method name in view ? - by sknair143 - 09-04-2023, 12:45 AM
RE: How to get method name in view ? - by kenjis - 09-04-2023, 01:09 AM
RE: How to get method name in view ? - by kenjis - 09-04-2023, 01:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB