PHPStorm 属性-读取 Yii 模型关系

PHPStorm property-read for Yii model relations

我如何在 PHPStorm 中执行此操作,以便在调用 model() 方法时提示正常工作?

例如:

/**
 * @property-read \Stores $store
 */
class Items extends CActiveRecord
{
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function relations()
    {
        return array('store' => array(self::BELONGS_TO, 'Stores', array('store_id' => 'id')),
    }
}

$items = new Items;
$items->store; // PHPStorm type hints this correctly

Items::model()->store; // PHPStorm does NOT type hint correctly.

此post.

的重点是极简主义之上的模型

你只需要'tell'PhpStorm这个方法returns。

    /**
     * @param $className
     * @returns Items
     */
    public static function model( $className = __CLASS__ ) {
        return parent::model( $className );
    }