A
A
Albert Tobacco2015-07-28 17:59:22
Yii
Albert Tobacco, 2015-07-28 17:59:22

How to add comments for locator service in Yii 2?

I use phpstorm, I love it when all variables are prompted and highlighted.
Where can I specify that Yii::$app->cart is an instance of /some/namespace/Cart ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Khomenko, 2015-07-28
@bighoc

There is a solution from Alexander Makarov : https://github.com/samdark/yii2-cookbook/blob/mast...
I also got a little tired that the autocomplete for my components does not work. What you have to do all the time:

/** @var LanguageManager $languageManager */
$languageManager = Yii::$app->languageManager;

While the variant from Alexander Makarov did not check.
Added:
I tried it today, it seems to work fine.
I created autocomplete.php at the root, where I placed my components:
class Yii extends \yii\BaseYii
{
    /**
     * @var BaseApplication|WebApplication|ConsoleApplication
     */
    public static $app;
}

/**
 * @property backend\components\bootstrap\SectionTreeManager $sectionTreeManager
 * @property backend\components\constructor\Component        $constructor
 * @property backend\components\rbac\SystemAuthManager       $systemAuthManager
 * @property backend\components\rbac\UserAuthManager         $userAuthManager
 * @property common\components\language\LanguageManager      $languageManager
 * @property common\components\view\ViewBlockManager         $viewBlock
 */
abstract class BaseApplication extends \yii\base\Application {}

/**
 * @property backend\components\bootstrap\SectionTreeManager $sectionTreeManager
 * @property backend\components\constructor\Component        $constructor
 * @property backend\components\rbac\SystemAuthManager       $systemAuthManager
 * @property backend\components\rbac\UserAuthManager         $userAuthManager
 * @property common\components\language\LanguageManager      $languageManager
 * @property common\components\view\ViewBlockManager         $viewBlock
 */
class WebApplication extends \yii\web\Application {}

/**
 * @property backend\components\bootstrap\SectionTreeManager $sectionTreeManager
 * @property backend\components\constructor\Component        $constructor
 * @property backend\components\rbac\SystemAuthManager       $systemAuthManager
 * @property backend\components\rbac\UserAuthManager         $userAuthManager
 * @property common\components\language\LanguageManager      $languageManager
 * @property common\components\view\ViewBlockManager         $viewBlock
 */
class ConsoleApplication extends \yii\console\Application {}

After that, in the IDE, you need to mark the @vendor/yiisoft/yii2/Yii.php file as text so that the IDE does not swear at 2 Yii classes in the global space.

M
Mikhail Osher, 2015-07-28
@miraage

I created a file with shortcuts, and wrote something like this:
// EDIT
I ​​thought it was Yii first version. But you can do the same with the second one.

/** @return CWebApplication|CConsoleApplication */
function app()
{
  return Yii::$app;
}

/** @return CHttpRequest */
function req()
{
  return Yii::$app->getComponent('request');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question