Welcome Guest, Not a member yet? Register   Sign In
URL Routing without using controller names
#1

(This post was last modified: 04-26-2018, 07:56 AM by CINewb.)

Hi there,

What I would like to do is create "pretty" URL's which don't feature the controller name.

So instead of:
  • website.com/category/bath-toys
  • website.com/product/rubber-duck
  • website.com/page/some-generic-page
I would like:
  • website.com/bath-toys
  • website.com/rubber-duck
  • website.com/some-generic-page
Each respective URL should load either the category, product or page controller.  My business logic already ensures that a URI cannot be used more than once.

So far I have done the following:

1) In config/routes.php I have set `$route['404_override'] = 'index';`

2) I've created a library called Item_type which inspects the requested URI and queries database tables to find out whether the requested URI is for a category, product or page.

3) I've created an `Index` controller which as per the 404_override receives any request which doesn't match a controller, calls the Item_type library to determine what the user is requesting, and then calls the relevant sub-controller from there.

I guess my question is: is there a better way of doing this?
Reply


Messages In This Thread
URL Routing without using controller names - by CINewb - 04-26-2018, 07:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB