如何从构造函数获取访问权限并处理变量?
当我初始化我的函数你好时,我得到错误:
消息:未定义的变量:type2
库:
class MyLibrary {
public function __construct($params)
{
echo $params['type'];
//I WANT TO DISPLAY TYPE2 BY HELLO FUNCTION
$type2 = 'asdasdasd';
}
public function hello(){
return $type2;
}
}
我的控制器:
public function test()
{
$params = array('type' => 'large', 'color' => 'red');
$this->load->library('TwitterAPI', $params);
//I WANT TO DISPLAY $TYPE2
echo $this->twitterapi->hello();
}
答案 0 :(得分:2)
创建一个私有成员变量:
$(".questionText").html(Question[randomNum1][randomNum2]);