Reputation: 918
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.
Upvotes: 0
Views: 247
Reputation: 4634
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.
Upvotes: 1