在 PHPStorm 中,通过向 config/autocomplete.php 添加一个包含属性的文件,我已经能够使用 Codeigniter 获得自动完成功能。 PhpStorm 能够读取此文件,并允许我快速导航到该函数并具有自动完成功能。在 autocomplete.php 中,我可以有 @property Account_model $Account_model
,然后每当我使用 $this->Account_model->xxx
时,自动完成工作。
当使用 get_instance()
时,所有这些功能都会消失。例如,在辅助类中,我必须使用 $CI = & get_instance();
,然后是 $CI->Account_model->xxxx
。以这种方式引用库时,如何让自动完成工作?
[注意:这只是一个简单的例子。我的真实用法是与 PHPUnit 一起使用,但解决上面的示例将使 PHPUnit 也能正常工作。]
最佳答案
要将 get_instance()
重新绑定(bind)到您的 IDE 的自动完成功能,您需要通知它这是 CodeIgniter 的 native Controller 的实例。这是CI_Controller
:
/**
* Example MyClass Library within
* /application/libraries/
**/
class MyClass {
/**
* @var CI_Controller
**/
private $ci;
/**
* Init MyClass
**/
public function __construct()
{
$this->ci =& get_instance();
}
}
关于php - 使用 get_instance() 时自动完成 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34952006/