Welcome Guest, Not a member yet? Register   Sign In
Creating a controller for serving static pages? *SOLVED*
#21

[eluser]Référencement Google[/eluser]
I don't know then, last thing I can do is post my page controller:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Page extends MY_Controller {

    /**
     * Constructor
     *
     * @access    public
     */
    function Page()
    {
        parent::MY_Controller();
    }

    // --------------------------------------------------------------------

    /**
     * Initial Method
     *
     * @access    public
     */
    function index()
    {
        $this->show();
    }

    // --------------------------------------------------------------------

    /**
     * Display the page passed as uri segment
     *
     * @access    public
     */
    function show($url = FALSE)
    {
        $this->template->page($url);
    }

}

/* End of file page.php */
/* Location: ./application/controllers/page.php */

Note that I use a custom template lib with this method inside:

Code:
/**
     * Display Global View Elements
     *
     * @access    public
     * @param    mixed    some data
     */
    function page($url = FALSE, $data = array())
    {
        // If no URL was set, redirect to the home page
        if( ! $url)
        {
            redirect();
        }

        // If the requested file don't exist, we display a 404
        if( ! file_exists(APPPATH.'views/pages/'.$url.EXT))
        {
            show_404();
        }

        // Send output to the browser
        $this->display('pages/'.$url, $data);
    }
#22

[eluser]iDenta[/eluser]
I got it working with a little rebuilding of the controller! No modification done to your MY_Router code done.

This works for me:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Page extends Controller {

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

    function index()
    {
        $this->show();
    }

    function show($url = FALSE, $data = array())
    {
        // If no URL was set, redirect to the home page
        if( ! $url)
        {
            redirect();
        }

        // If the requested file don't exist, we display a 404
        if( ! file_exists(APPPATH.'views/pages/'.$url.EXT))
        {
            show_404();
        }

        // Send output to the browser
        $this->load->view('pages/'.$url, $data);
    }
}
#23

[eluser]Référencement Google[/eluser]
great then !
#24

[eluser]iDenta[/eluser]
I have no idea if this i coded properly, but it works som i'm happy!

Thank you so much for your time TooPixel! Smile
#25

[eluser]Référencement Google[/eluser]
Welcome Wink




Theme © iAndrew 2016 - Forum software by © MyBB