Should I add database queries to Codeigniter Routes.php?
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:开发者_Go百科
"page/get_page/$1"
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.
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.
精彩评论