Welcome Guest, Not a member yet? Register   Sign In
How to set global variable in Library?
#1

[eluser]geshan[/eluser]
I'm coding a code igniter library, for pagination I need to make the total_rows variable global(accessible in all the functions of the library). I can't set the variables thought they are set to var xyz just after class { start. I can set them from the constructor but can't set them from other functions, how can I do it? Are there any specials ways to do that except $this->global_var= $any_var;

Code:
class Testlib{
    
    var $output=;
    var $settings;
        var $total_rows;

    function Testlib($params){
        $this->total_rows=15;// it works
        $this->total_rows=$param['total_rows'];//also works
    }//constructor close

    function setTotalRows(){
     $this->total_rows=25; //does not work
    
    //even the code below does not work...
    $query_res['no_of_rows']=$query_exe->num_rows();
     $this->total_rows=$query_res['no_of_rows'];
    }//function setTotalRows close
}//class close

How can I do it, or is it happening due to the page reload? suggest and help.
#2

[eluser]wiredesignz[/eluser]
Firstly they aren't global, they are class variables. And you are posting this in the wrong forum. Tongue

If you call $this->testlib->setTotalRows(); you should see the changes providing there are no other errors.

Code:
var $output=; //<- this will cause an error

You can use print_r($this->testlib); to see the values after the call.




Theme © iAndrew 2016 - Forum software by © MyBB