Welcome Guest, Not a member yet? Register   Sign In
How to check if you're in a controller subfolder?
#1

[eluser]Unknown[/eluser]
Hello!
Is there any "clean" way to check if you're in a controller subfolder?

On one of my websites you have the following structure:

controllers / products
controllers / admin /
controllers / admin / products

I know I can check it through URI segment, but I don't believe this is a good way to do this, once in some of the environments that the system runs it is in a subfolder, so the uri segment would vary.

I tried also using the router object, using the fetch_class method, but it'll return just the controller name itself (products for controllers / products and also for controllers / admin / products).

Can you guys help me out?

Thanks!
#2

[eluser]PhilTem[/eluser]
This undocumented function in CI::Router should help you:

Code:
/**
* Fetch the sub-directory (if any) that contains the requested controller class
*
* @access public
* @return string
*/
function fetch_directory()
{
    return $this->directory;
}

At least it works for me getting the directory - even though I think it doesn't work properly with @wiredesignz HMVC, but I might be wrong with that one.
#3

[eluser]CroNiX[/eluser]
Yes, what PhilTem suggested is what you should use and what CI uses internally to figure out if a request contains a directory before the controller/method/params in order to load the right controller.




Theme © iAndrew 2016 - Forum software by © MyBB