我的IDE PHPStorm将下一行标记为错误(单词"password")
Yii::$app->passport->getLoginUrl($Url);
Run Code Online (Sandbox Code Playgroud)
我怎么能为它写phpdoc.
可能是这样或怎么样?
/** @var $Yii::$app->passport array */
Yii::$app->passport->getLoginUrl($Url);
Run Code Online (Sandbox Code Playgroud)
您可以在Yii 2.0 Cookbook中找到解决方案- 自定义组件的IDE自动完成
使用自定义Yii类
给IDE一些提示的最好方法是使用你自己的Yii文件,这个文件在运行代码时实际上并没有使用.可以命名此文件
Yii.php,内容可能如下:
<?php
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
*/
class Yii extends \yii\BaseYii
{
/**
* @var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* @property \app\components\RbacManager $authManager The auth manager for this application. Null is returned if auth manager is not configured. This property is read-only. Extended component.
* @property \app\components\Mailer $mailer The mailer component. This property is read-only. Extended component.
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
*
* @property \app\components\User $user The user component. This property is read-only. Extended component.
* @property \app\components\MyResponse $response The response component. This property is read-only. Extended component.
* @property \app\components\ErrorHandler $errorHandler The error handler application component. This property is read-only. Extended component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*
* @property \app\components\ConsoleUser $user The user component. This property is read-only. Extended component.
*/
class ConsoleApplication extends yii\console\Application
{
}
Run Code Online (Sandbox Code Playgroud)
在上述PHPDoc的
BaseApplication,WebApplication,ConsoleApplication将通过IDE被用于自动填充通过描述你的定制组件@property.注意:要避免"多个实现"PHPStorm警告并使自动填充更快排除或"标记为纯文本"
vendor/yiisoft/yii2/Yii.php文件.而已.现在
Yii::$app->user将是我们的\app\components\User组件而不是默认组件.这同样适用于所有其他@property声明的组件.
| 归档时间: |
|
| 查看次数: |
1377 次 |
| 最近记录: |