Welcome Guest, Not a member yet? Register   Sign In
Default static page controller?
#1

[eluser]copernicus[/eluser]
I have a site that contains about half dynamic and half static pages, right now I have a controller for every static page but they only set the page title, load the navigation and then a view. Is there a way I can have just one controller that handles all static pages with each function inside it loads the correct view? Is there a way to do this without writing 10-15 routing rules?
#2

[eluser]Crimp[/eluser]
Sure, just make one page controller that has methods for each static page: /page/static. The static method then simply loads the view. It all depends on your prefs. for an URL scheme.
#3

[eluser]Phil Sturgeon[/eluser]
Lifting some code from Dyllon to do this, modified of course.

application/libraries/My_Router.php

Code:
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("pages",$segments[0]);
            
        }
    }
    return parent::_validate_request($segments);
}




Theme © iAndrew 2016 - Forum software by © MyBB