Welcome Guest, Not a member yet? Register   Sign In
$this->_remap('home') sends index instead of home.
#5

[eluser]Bramme[/eluser]
Oh, right.

Here's the code:

Code:
function _remap($method){

    if($method == 'index') $method = 'home';

    $pages = $this->mdl_content->get_pages();
    
    if ($pages !== FALSE)
    {
        foreach ($pages as $key => $page)
        {
    
            if (strtolower(url_title($page['title'])) == strtolower(url_title($method)))
            {
                $this->load->model(array('mdl_sidebar', 'mdl_gallery'));
                
                $content = $this->mdl_content->place_galleries($page['content']);
            
                $this->template->write('_content', $content);
                $data['items'] = $this->mdl_sidebar->get_items($key);
                $this->template->write_view('_sidebar', 'sidebar', $data);    
                    
                $this->template->add_js('assets/js/jquery.js');
                $this->template->add_js('assets/js/galleryview/jquery.timers.js');
                $this->template->add_js('assets/js/galleryview/jquery.galleryview.js');
                $this->template->add_js('assets/js/galleries.js');
                $this->template->add_css('assets/css/galleryview.css');
                
                $this->template->render();
                return;
            }
        }
    }
    elseif (method_exists($this, $method))
    {
        $this->$method();
    }
    elseif ($pages === FALSE)
    {
        show_error('I can\'t find any pages yet!');
    }
    else
    {
        show_404($method);
    }
}
Basically, it checks the database first to see if any of the pages in the database match the requested page, if not, it checks the other methods in the frontend controller (handy for pages that need further processing: news, contact etc...), if none of those are found (because there were no pages in the db) an error is shown that there are no pages yet and if none of those are met, show a 404 error.


Messages In This Thread
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 10:34 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 11:04 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 11:09 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 11:18 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 11:26 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 11:45 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 11:58 AM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 12:09 PM
$this->_remap('home') sends index instead of home. - by El Forum - 04-29-2009, 01:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB