0

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.

2
  • 1
    use codeigniter config routes file ellislab.com/codeigniter/user-guide/general/routing.html Commented 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? Commented Jun 9, 2014 at 13:10

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.