views:

30

answers:

2

All of the pages and resources that php will give through readfile() exist in a database table entities. The entities table includes the uri alias for the object, what type of object it is so it can properly route it. Should I just include it in application/config/routes.php, should I write some helper functions and include them in the application/config/routes.php?

Should I put this elsewhere?

example:

URI:
  index.php/about-us

SQL:
  SELECT *
  FROM entities
  WHERE alias LIKE ?

RESULT:
  array(
    [id]=>5
    [alias]=>'about-us'
    [type]=>'page'

ROUTE:
  "page/get_page/$1"
A: 

Any data access you do should be done through models. If I'm not mistaken, I believe you can call your models directly from Routes.php (meaning the CI object should be instantiated), but you may want to test this first.

treeface
+1  A: 

What I would recommend is that you subclass CodeIgniter's router (discussed here: CodeIgniter System Subclassing), and make your calls in there. This way you keep your routes in your routes config, and your routes logic in the router class.

This way you'll be able to put whatever routing related functions that are necessary in the same class, as well.

tomlikestorock