Welcome Guest, Not a member yet? Register   Sign In
Basic Page Function
#6

(This post was last modified: 10-24-2014, 10:04 AM by navotjer.)

I usually use MY_Controller and load the view like so (example only)(if anybody has some thoughts about my way, please, make me smarterSmile ):

Code:
class MY_Controller extends CI_Controller
{
    /*
     * Everything else you need
     */

    protected function render($views, $data = FALSE, $css = FALSE, $js = FALSE)
    {
     //get BASE css files, append new if needed
     $head['css'] = $this -> addCss($css);
     //metadata
     $head['metaData'] = $this -> metaData;
     //get BASE scripts, append new if needed
     $addJs['js'] = $this -> addJs($js);
     $this -> load -> view('page/head_view', $head);
     $this -> load -> view('page/header_view');
     $this -> load -> view('page/sidebar_view');
     if ($views === FALSE)
     {
    $this -> load -> view('page/content_view', $data);
     }
     else
     {
        if (is_array($views))
        {
            foreach ($views as $view)
        {
            $this -> load -> view($view, $data);
        }
        }
       else
       {
           $this -> load -> view($views, $data);
        }
     }
    $this -> load -> view('page/content_end_view');
    $this -> load -> view('page/footer_view', $addJs);
    }
}

Then in Some_controller:

Code:
<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Index extends MY_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
                $data = $this -> getDataFromSomewhere();
        $this -> render('', $data);
                //Or if I want a special "content" view
                $this -> render('name_of_view',$data);
    }

}

Thank you for the #EOF tip.
*Edit -> BB code tags...
Reply


Messages In This Thread
Basic Page Function - by Tux - 10-22-2014, 12:48 AM
RE: Basic Page Function - by Rufnex - 10-22-2014, 01:27 AM
RE: Basic Page Function - by John_Betong - 10-22-2014, 06:16 AM
RE: Basic Page Function - by John_Betong - 10-22-2014, 06:20 AM
RE: Basic Page Function - by Rufnex - 10-22-2014, 09:45 AM
RE: Basic Page Function - by navotjer - 10-24-2014, 04:29 AM
RE: Basic Page Function - by jlp - 10-25-2014, 06:35 AM
RE: Basic Page Function - by puppy - 11-04-2014, 08:11 AM
RE: Basic Page Function - by kilishan - 10-25-2014, 08:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB