时间过去了,我找到了解决办法
诀窍是您可以在 cmets 中返回 @return static,这正是 PHPStorm 检测正确类所需要的,因此让我们创建一个扩展 CActiveRecord 并具有正确文档 cmets 的 BaseModel /p>
所以把class MyClass extends CActiveRecord改成class MyClass extends BaseModel
在使用这个的时候,现在所有的类提示都可以工作了 :)
<?php
/**
* Extension of the default Yii Active Record class
*
* Edit this class to add custom behaviour to all the models used within the application
*
*/
class BaseModel extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* Uses the class that called the model() by default
* @param string $className active record class name.
* @return static The static model class instance
*/
public static function model($className = null)
{
return parent::model($className !== null ? $className : get_called_class());
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param mixed $pk
* @param string $condition
* @param array $params
* @return static
*/
public function findByPk($pk,$condition='',$params=array())
{
return parent::findByPk($pk,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param string $condition
* @param array $params
* @return static
*/
public function find($condition='',$params=array())
{
return parent::find($condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param string $condition
* @param array $params
* @return static[]
*/
public function findAll($condition='',$params=array())
{
return parent::findAll($condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $pk
* @param string $condition
* @param array $params
* @return static[]
*/
public function findAllByPk($pk,$condition='',$params=array())
{
return parent::findAllByPk($pk,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $attributes
* @param string $condition
* @param array $params
* @return static
*/
public function findByAttributes($attributes,$condition='',$params=array())
{
return parent::findByAttributes($attributes,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $attributes
* @param string $condition
* @param array $params
* @return static[]
*/
public function findAllByAttributes($attributes,$condition='',$params=array())
{
return parent::findAllByAttributes($attributes,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $sql
* @param array $params
* @return static
*/
public function findBySql($sql,$params=array())
{
return parent::findBySql($sql,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $sql
* @param array $params
* @return static[]
*/
public function findAllBySql($sql,$params=array())
{
return parent::findAllBySql($sql,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* This will add a couple of milliseconds with every `with` usage
* @return static
*/
public function with()
{
return call_user_func_array('parent::with', func_get_args());
}
/**
* This function exists only to help the IDE autodetect the returned class
* @return static
*/
public function together()
{
return parent::together();
}
}