Database driven routes in CodeIgniter |
[eluser]neillyons.co[/eluser]
See updated version of this here Using a pre_system hook the routes array can be populated from your database. A route is a CodeIgniter controller action alias. Used to build search engine friendly sites. eg posts/database-driven-routes-in-codeigniter is mapped to posts/get/2 Step 1 Define the hook by inserting the code below into the hooks.php file ( ..system/application/config/hooks.php ). Code: require_once BASEPATH."application/config/database.php"; Step 2 Create a file called Router_Hook.php in the hooks directory ( ..system/application/hooks/Router_Hook.php ) and insert the code below. Code: if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: id, route, controller, created, updated Step 3 Insert the code below into the routes.php file ( ..system/application/configs/routes.php ) after the scaffolding trigger. Code: global $DB_ROUTES; Step 4 In the config.php file ( ..system/application/configs/config.php ) set enable hooks to TRUE. Code: $config['enable_hooks'] = TRUE; This technique will work as it is, but I recommend using DataMapper to save routes to the database aswell. Below is my route datamapper model. Code: class Route extends DataMapper Insert the code below at the bottom of the inflector_helper.php file ( ..system/application/helpers/inflector_helper.php ) Code: /** Let me know what you think of this feature. |
Messages In This Thread |
Database driven routes in CodeIgniter - by El Forum - 06-28-2009, 10:04 AM
Database driven routes in CodeIgniter - by El Forum - 07-01-2009, 11:42 AM
Database driven routes in CodeIgniter - by El Forum - 07-01-2009, 12:00 PM
Database driven routes in CodeIgniter - by El Forum - 07-01-2009, 12:32 PM
Database driven routes in CodeIgniter - by El Forum - 07-01-2009, 01:41 PM
Database driven routes in CodeIgniter - by El Forum - 07-03-2009, 02:41 PM
Database driven routes in CodeIgniter - by El Forum - 07-03-2009, 03:36 PM
Database driven routes in CodeIgniter - by El Forum - 01-25-2010, 06:30 PM
Database driven routes in CodeIgniter - by El Forum - 02-21-2010, 04:22 AM
Database driven routes in CodeIgniter - by El Forum - 05-15-2010, 04:01 AM
Database driven routes in CodeIgniter - by El Forum - 05-15-2010, 06:29 AM
Database driven routes in CodeIgniter - by El Forum - 05-19-2010, 01:40 PM
Database driven routes in CodeIgniter - by El Forum - 05-20-2010, 02:42 AM
|