Welcome Guest, Not a member yet? Register   Sign In
Retrieving the default controller config item
#1

[eluser]NemetraL[/eluser]
Hello,

The problem is: I'd need to retrieve
Code:
$route['default_controller'];
from a post-controller-constructor hook.

There's the raw way, which consists in copying the Router library code directly inside the hook:
Code:
// Load the routes.php file.
@include(APPPATH.'config/routes'.EXT);
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);
The point is: this file has already been loaded and the class has already been created (in the system/codeigniter/CodeIgniter.php file, under the name $RTR).

But once the controller is loaded, I can't find it anymore :-S

Any idea?
#2

[eluser]NemetraL[/eluser]
Gosh I posted that too fast..

A simple:
Code:
$ci =& get_instance();
$ci->uri->router->routes['default_controller'];
is what I was looking for. I found it using:
Code:
var_dump($ci);
Problem solved.

PS: it's incredibly useful to var_dump() the main controller from time to time to remember all the things it carries with it along the code execution ;-).
#3

[eluser]John_Betong[/eluser]
Hi NemetraL,

Have you tried?

Code:
echo "<br /><pre>";
    print_r($ci);
  echo "</pre>";
&nbsp;
or
Code:
echo "<br /><pre>";
    print_r($this);
  echo "</pre>";
&nbsp;
&nbsp;
#4

[eluser]NemetraL[/eluser]
Yes the problem is solved now.

I had to go through the var_dump(), which default layout is less readable than the print_r() by the way ;-).
#5

[eluser]stormbytes[/eluser]
I wonder if there's a way to do this using CI 2.02 ?

I tried your method and it returns an error.




Theme © iAndrew 2016 - Forum software by © MyBB