通过$此加载功能时,当我使用像这样一类内调用函数中使用变量:无法在笨
protected $_mdl = 'mdl_posts_latest';
function __construct()
{
parent::__construct();
$this->load->model($this->$_mdl);
}
public function index()
{
$offset = 0;
$limit = 5;
$data['p_latest'] = $this->mdl_posts_latest->get_posts_latest($offset, $limit);
...
...
...
.
,它是工作。
问题是,当我RY是这样的:
$data['p_latest'] = $this->$this->$_mdl->get_posts_latest($offset, $limit);
它抛出这个错误:
类Posts_latest的对象不能转换为字符串
,因为,很明显,此代码是错误的:$this->$this->$_mdl->
因此,我的问题是我如何才能在我的课程顶部定义一次我的模型的名称,然后将其用作所有调用函数的调用中的变量等。
因为现在我不知道该怎么做它,所以它看起来像什么:
$this->$model->get_something();