I am building a cms in codeigniter and i want to remove controller name and function name form the url and just print the alias. I will be having two controllers one for static pages and other for blog posts with categories. Please help, Suggestions reagrding modification of two controllers are also welcome.
-
1use codeigniter config routes file ellislab.com/codeigniter/user-guide/general/routing.htmlaseferov– aseferov2014-06-09 13:03:41 +00:00Commented Jun 9, 2014 at 13:03
-
I looked into that and was not able to make it function according to my need. Can anybody explain in detail?Opax Web– Opax Web2014-06-09 13:10:17 +00:00Commented Jun 9, 2014 at 13:10
1 Answer
You will need to override the default 404 controller in application/config/routes.php.
$route['404_override'] = 'content';
Any request that can't be mapped to a controller will be passed to the application/controllers/content.php controller
Your Content controller, or whatever you decide to call it, will parse the uri [$this->uri->segment(1)] and check for a matching reference in your CMS database.
If there is no match in the database, then you can look for a static view in the views folder and load it.
if(is_file(FCPATH.'views/'.$this->uri->segment(1).'.php')) {
$this->load->view($controller,$this->data);
}
If no static view is found, and there is no matching content in the db, call the show_404() function.
Using this method, you will keep the default CI functionality of uri mapping, so at any time, you can add controllers as you normally would and the app will perform like a vanilla CI install.