Welcome Guest, Not a member yet? Register   Sign In
Default method?
#1

[eluser]feejin[/eluser]
This is probably easy but I'm not sure what to search for!

I have my site working as:

Code:
http://www.website.com/pages/index/name-of-page

So it's using the 'pages' controller, using the default 'index' method and passing it 'name-of-page' as an argument. For neatness, I would like to just to be:

Code:
http://www.website.com/pages/name-of-page

I've achieved this with the code below, but it feels clunky and am wondering if there's a better way of doing it? I've a feeling it might be better done with routes but would like a push in the right direction!

Thanks,
Colin

Code:
class Pages extends Controller {

    function Pages()
    {
        parent::Controller();    
    }

    function _remap($method)
    {
        $this->index();
    }

    function index($get_page = '')
    {


        if ( ! ($get_page = $this->uri->segment(2,0)) )
        {
            $get_page = $this->config->item('page_default');
        }
    
        // continue looking up page content
    }
}
#2

[eluser]Clooner[/eluser]
You can easily use the routes for this. It is described in the manual : http://ellislab.com/codeigniter/user-gui...uting.html
Code:
$route['pages'] = "pages/index";
$route['pages/(:any)'] = "pages/index/$1";
#3

[eluser]feejin[/eluser]
Thanks, I thought it might be to do with routes but before pursuing it I wanted to make sure I was on the right... route Smile
#4

[eluser]mattpointblank[/eluser]
Just bear in mind with this approach that if you add any functions to your Pages controller, you'll have to manually re-route them in the routes.php file before they'll work, otherwise they'll be treated as arguments to index().




Theme © iAndrew 2016 - Forum software by © MyBB