a variable for multi function.?
did can be defined a variable for multi function(in codeigniter)? how is it?
because i must use of a value similar in multi funct开发者_如何学JAVAion.
like:
class Home extends CI_Controller {
$hi = 'hello'
function one() {
echo $hi;
}
function tow() {
echo $hi;
}
}
what about doing something like this
class Home extends CI_Controller {
protected $_hi = 'hi';
function one() {
echo $this->_hi;
}
function tow() {
echo $this->_hi;
}
}
if the hi is a constant you have better to use the const keyword
class Home extends CI_Controller {
const HI = 'hi';
function one() {
echo self::HI;
}
function tow() {
echo self::HI;
}
}
last point if that constant is used in more than one controller you have better to create a separate class and define the constant in that class.
class Home extends CI_Controller {
protected $_find;
function __construct() {
parent::__construct();
$this->_find = $this->input->post('find');
}
function one() {
echo $this->_find;
}
function tow() {
echo $this->_find;
}
}
one remark with the last code snipet, I am not an codeigniter expert so not sure if you can do $this->input->post('find')
would work in the constructor
精彩评论