Reputation: 12163
In Ci, how do I grab a variable from another method inside the same class?
Upvotes: 2
Views: 4388
Reputation: 13630
You'll have to set it as a class variable and use that.
Something like:
<?php
class Blog extends CI_Controller {
$my_variable = null;
function _set_myvariable()
{
$this->my_variable = "this variable has a value";
}
function get_variable()
{
echo $this->my_variable; // outputs NULL
$this->_set_myvariable();
echo $this->my_variable; // outputs "this variable has a value"
}
}
?>
calling the get_variable
method will:
_set_myvariable
private function (note the "_" starting the function name) that will set the class variable.Upvotes: 4