Within PHPStorm, I have been able to get autocomplete working with Codeigniter by adding a file to config/autocomplete.php which contains properties. PhpStorm is able to read this file, and allow me to quickly navigate to the function and have autocomplete capabilities. In autocomplete.php, I can have @property Account_model $Account_model
, and then whenever I use $this->Account_model->xxx
, autocomplete works.
When using get_instance()
, all of this functionality dies. For example, when in a helper class, I have to use $CI = & get_instance();
, and then $CI->Account_model->xxxx
. How do you get autocomplete to work when referencing the library this way?
[Note: this is just a simple example. My true usage is with PHPUnit, but solving the above example will allow PHPUnit to work as well.]
To re-bind get_instance()
to your IDE’s autocomplete, you'll need inform it that’s an instance of the native controller for CodeIgniter. Which isCI_Controller
:
/**
* Example MyClass Library within
* /application/libraries/
**/
class MyClass {
/**
* @var CI_Controller
**/
private $ci;
/**
* Init MyClass
**/
public function __construct()
{
$this->ci =& get_instance();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With