Php 库编写语法,比如模型/控制器?
使用CodeIgniter 2编写库时:Php 库编写语法,比如模型/控制器?,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,使用CodeIgniter 2编写库时: public function __construct() { $this->ci =& get_instance(); $this->ci->load->model('one_model'); } public function test() { $this->ci->one_model->blabla(); } 我对这个库很好奇,我能用controller/model风格写
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->model('one_model');
}
public function test()
{
$this->ci->one_model->blabla();
}
我对这个库很好奇,我能用controller/model风格写它吗(不用->ci)
我这样问是因为我有时会将模型代码作为库重新编写,以实现更好的逻辑-数据库分离谢谢你的帮助,谢谢
只需在课堂上使用
\u get
函数即可
class Custom
{
public function __construct()
{
// construct
}
public function __get($var)
{
return get_instance()->$var;
}
public function test()
{
$this->one_model->blabla();
}
}
太多了,波拉。我已经看过很多次了,但不知道它是干什么用的。
class Custom
{
public function __construct()
{
// construct
}
public function __get($var)
{
return get_instance()->$var;
}
public function test()
{
$this->one_model->blabla();
}
}