Welcome Guest, Not a member yet? Register   Sign In
Passing variables to all views.
#5

(This post was last modified: 04-11-2015, 05:05 AM by casa.)

if you want to pass all the time the same variables in all the views and this variables not change, you can do like you say : extend CI_Controller with your MY_Controller and after all your controllers extend MY_Controller.
Note that :
My_Controler.php will be in directory named "core" of the directorys "application". No need to put it in the directory "core" of your directory "system".
application/core/MY_Controller.php
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Controller extends CI_Controller
{
    private 
$items ;
    
    public function 
__construct()
    {
        
parent::__construct() ;
        
$this->init() ;
        
$this->load->vars($this->items );
    }
    
    private function 
init()
    {
        
$this->items = array('some_var' => '....',
                     
'new_var' => '...') ;
    }    

Your other controllers in directory Controller
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
extends MY_Controller
{
        private 
$vue '.......' ;

    public function 
__construct()
    {
        
parent::__construct() ;
    }
    
    
    public function 
index()
    {
        
$this->load->view($this->vue) ;
    }    

In your view
PHP Code:
$v $this->load->get_var('some_var') ; // or only call $some_var 
Reply


Messages In This Thread
Passing variables to all views. - by iM7md - 04-10-2015, 04:40 AM
RE: Passing variables to all views. - by gadelat - 04-10-2015, 07:36 AM
RE: Passing variables to all views. - by CroNiX - 04-10-2015, 08:03 AM
RE: Passing variables to all views. - by iM7md - 04-10-2015, 01:04 PM
RE: Passing variables to all views. - by casa - 04-11-2015, 04:38 AM
RE: Passing variables to all views. - by InsiteFX - 04-11-2015, 04:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB