phpcodeigniterhmvc

How to get Modules Name in HMVC Codeigniter


I have a couple of controllers in two modules with same name and both works fine. also i have a function for checking access permission, it uses $this->router->fetch_class().
problem is $this->router->fetch_class() returns controller name and it's the same. but i need Modules name too.

Structure of the Modules

/modules
    /product
        /controllers
            /product.php
            /options.php [1]
        /models
        /views
    /inventory
        /controllers
            /inventory.php
            /options.php [2]
        /models
        /views

and urls are:

[1]: ../product/options/function_name
[2]: ../inventory/options/function_name

so is there any way to check access permission without changing controllers name?


Solution

  • Like @sintakonte said, you can use the uri library.

    Using segment you can get each part of the url.

    Module names are always the first part after your domain.

    $module_name = $this->uri->segment(1);