Welcome Guest, Not a member yet? Register   Sign In
$this->load->vars($array)
#1

[eluser]Yash[/eluser]
$this->load->vars($array)

i use this as
Code:
function Blog()
    {
        parent::Controller();    
        $pr[]=1;
        $pr[]=2;
        $this->load->vars($pr);
        
    }
    
    function index()
    {
        
        echo $pr;
        
    }

not working ...

Please me how to use this.
#2

[eluser]Pascal Kriete[/eluser]
The load->vars function is used to pass variables to views (not to mention it extracts them). What you want here is a class variable.
Code:
class Blog {

    var $pr;

    function Blog()
    {
        parent::Controller();
        $this->pr = array(1, 2);
    }

    function index()
    {
        print_r($this->pr);
    ]
}
#3

[eluser]xwero[/eluser]
The load->vars function adds the array to an Loader class variable that is used in the load->view function where the array gets extracted.

So in order to use it you have to load a view file.

If you need a array that is accessible throughout the class you have to do this
Code:
class Blog extends Controller
{
    var $pr = array();

    function Blog()
    {
        parent::Controller();    
        $this->pr=array(1,2);
        
    }
    
    function index()
    {
        
        print_r($this->pr);
        
    }
}

EDIT : inparo beat me that makes it 1-1 this morning Smile
#4

[eluser]Yash[/eluser]
lol same coding style.

how to use $this->load->vars($array) ?
#5

[eluser]xwero[/eluser]
Code:
function Blog()
    {
        parent::Controller();    
        $pr['one']=1;
        $pr['two']=2;
        $this->load->vars($pr);
        
    }

function index()
    {
        
        $this->load->view('viewname');
        
    }
// viewname.php
<?php echo $one ?> and <?php echo $two ?>
#6

[eluser]Yash[/eluser]
ohh thanx I got it now




Theme © iAndrew 2016 - Forum software by © MyBB