matt matt - 1 year ago 106
PHP Question

CodeIgniter detect if Default Controller route was used

In CodeIgniter, is there a way to know if a user was sent to the Default Controller because the route sent them there, OR because the user actually entered that controller in the URL bar.

In other words, and could both send you to the 'home' controller, because you have set

$route['default_controller'] = 'home';

But only would invoke CI to fetch the "default_controller"
So, how do I detect this? If only there was a boolean function that could tell me this.

Answer Source

You should be able to use $this->uri->total_segments() ... or one of the other functions in the URI class to deduce this ...

if($this->uri->total_segments() === 0){
    //user came in by default_controller

URI Class Docs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download