Welcome Guest, Not a member yet? Register   Sign In
DRY this view?
#7

(09-13-2015, 07:56 AM)solidcodes Wrote: Here is the update for these codes,
I move the method into Application/Core/MY_controller.php
Code:
    /***
     *     author: warren nazareno
     *  email: [email protected]
     *  purpose: will DRY the view codes.
     ***/
    function sview($data=array())
    {
        $this->data['header']         = $this->load->view('/public/templates/header', $this->data, TRUE);
        $this->data['menu']         = $this->load->view('/public/templates/menu', $this->data, TRUE);
        $this->data['body']         = $this->load->view('/public/templates/body', $this->data, TRUE);
        $this->data['navleft']         = $this->load->view('/public/templates/navleft', $this->data, TRUE);
        $this->data['navright']        = $this->load->view('/public/templates/navright', $this->data, TRUE);                
        $this->data['footer']         = $this->load->view('/public/templates/footer', $this->data, TRUE);
        
        $this->load->view('/public/templates/master', $this->data);
    }

Because it's throwing me error message when I put it under helper.
And now it's working fine.
Again if you guys have better suggestion please let me know.


and you should create $data for header|footer|etc in all places where you need this header|footer|etc.

and what about if we hav header|footer|menu|etc as classes with on controllers,dates,viewers,etc andjust call it in needed places.

My working approach.

Code:
# cat ./MY_Loader.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Loader extends CI_Loader {

        protected $CI;

        public function __construct(){
            $this->CI =& get_instance();
        }

        public function commons($file_name,$method,$data = FALSE) {

                    $file_path = APPPATH . 'controllers/common/' . ucfirst($file_name) . '.php';
                    $object_name = $file_name;
                    $class_name = ucfirst($file_name);

                    if(file_exists($file_path)){
                            require_once $file_path;

                            $this->CI->$object_name = new $class_name();
                            $this->CI->$object_name->$method($data);

                    } else {

                            show_error("Unable to load the requested controller class: " . $class_name);
                    }
        }
}

And in any page just

$this->load->commons('header','index',$data_header);
$this->load->commons('left','index');
$this->load->view('client_list',$data);
$this->load->commons('right','index');
$this->load->commons('footer','index');
Reply


Messages In This Thread
DRY this view? - by solidcodes - 09-12-2015, 10:09 PM
RE: DRY this view? - by solidcodes - 09-13-2015, 07:24 AM
RE: DRY this view? - by solidcodes - 09-13-2015, 07:56 AM
RE: DRY this view? - by pdthinh - 09-13-2015, 08:40 AM
RE: DRY this view? - by wishmaster - 09-13-2015, 10:20 PM
RE: DRY this view? - by solidcodes - 09-13-2015, 08:01 AM
RE: DRY this view? - by solidcodes - 09-13-2015, 08:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB