Question

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, ---.com/home and ---.com could both send you to the 'home' controller, because you have set

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

But only ---.com/ 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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top