Routing in CodeIgniter for (:any)

I’m trying to make my CodeIgniter application work similarly to WordPress.

I want to be able to make these kind of URLs:

My routing:

$route['(:any)'] = "core/index/$1";

Which will call my Core controller and pass the page name into the index function.

I then lookup in my database for the page name and display the page to the user. So far so good.

However, there will be times when I want to call another controller. For example:

Now I assume my route will just grab all these rules and send them into my Core controller. Is there a way to make an exception for certain pages? Or is it a good idea to do this check inside my Core controller.

For example,

if ($page not in DB) {
   // Call controller/method

This seems a little redundant since I just want CodeIgniter to handle this.

Any suggestions?


Read more here: Routing in CodeIgniter for (:any)

Leave a Reply

Your email address will not be published. Required fields are marked *