M
M
Maxim Ivanushchik2013-11-05 15:55:21
phpstorm
Maxim Ivanushchik, 2013-11-05 15:55:21

Yii: autocompletion for model methods not working in PHPStorm?

There is an AjaxController.php controller.
In the init() of the controller, objects are created - instances of classes:

public function init() {<br>
    ...<br>
    // init classes<br>
    $this->_oModelSite = new Site;<br>
    $this->_oHelperText = new HelperText;<br>
    ...<br>
  }<br>

For some reason, autocompletion does not work in the methods of this class (controller) (for example, for the processPostArray method from the HelperText class):
public function actionAutoBrand() {<br>
    ...<br>
    // getting POST data<br>
    $sBrand = $this->_oHelperText->processPostArray($_POST['brand']);<br>
    ...<br>
  }<br>

If you create an instance of the class directly in the controller method, then everything works well. But for some reason it doesn't work with init().
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Medved, 2013-11-05
@makis

Time to start using PHPDoc

/**
 @var Site
*/
protected $_oModelSite;
/**
 @var HelperText
*/
protected $_oHelperText;

Why is there an "o" at the beginning? And it is also clear that this is an instance, not a type.
Now there is full encapsulation, there is no need to write the "_" prefix to let you know that this is a private type.

A
Andrey Smirnov, 2013-11-05
@Melorian

In this case, most likely, PHPStorm simply does not know that the init function is called somewhere in advance, in which class instances are created. It is possible to try to work around this by directly adding a call to the init function to __construct, or to inherit __construct by instantiating it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question