Welcome Guest, Not a member yet? Register   Sign In
How to get the default controller?
#1

[eluser]kilishan[/eluser]
I've just started working on a new view library that will function much like Rails' layouts, and I've hit one stumbling block: when the total uri segments is 0, I need to find the name of the default controller.

Is there any way to do this from within a library?

Thanks!
#2

[eluser]xwero[/eluser]
the default controller is located in the config routes file to get it you could include the file or you could extend the router library
Code:
class MY_Router extends CI_Router
{
    function MY_Router()
    {
      parent::CI_Router();
    }

    function getdefault()
    {
       return $this->default_controller;
    }
}
#3

[eluser]xwero[/eluser]
Oops the routing library isn't accessible but you could extend the URI library or add
Code:
$this->router =& load_class('Router');
To your own l library but it might be a bit overkill if you only going to use it to get the default controller
Extending the URI would be
Code:
class MY_URI extends CI_URI
{
    function MY_URI()
    {
      parent::CI_URI();
    }

    function getdefault()
    {
       return $this->router->default_controller;
    }
}
#4

[eluser]kilishan[/eluser]
Excellent! Just what I was looking for, thanks!

I'll give that a go tonight.




Theme © iAndrew 2016 - Forum software by © MyBB