【发布时间】:2012-05-26 17:15:46
【问题描述】:
当我使用 find()、findAll()、findByAttributes() 等时,我希望 PhpStorm 自动完成我的模型属性...
我有一个这样的模型:
/**
* member model parameters:
* @property integer $id
* @property integer $city_id
* @property string $e_mail
*/
class Member extends CActiveRecord
{
/**
* @static
* @param string $className
* @return Member
*/
public static function model($className = __CLASS__)
{
return parent::model($className);
}
...
当我使用主动记录方法时:
$member = Member::model()->findByAttributes(array('e_mail'=>'Foo Bar'));
并在我写这篇文章时尝试自动完成:
$member->
它只给了我列表中CActiveRecord的参数和方法。
我试图改变
/**
* Finds a single active record that has the specified attribute values.
* See {@link find()} for detailed explanation about $condition and $params.
* @param array $attributes list of attribute values (indexed by attribute names) that the active records should match.
* An attribute value can be an array which will be used to generate an IN condition.
* @param mixed $condition query condition or criteria.
* @param array $params parameters to be bound to an SQL statement.
* @return CActiveRecord the record found. Null if none is found.
*/
public function findByAttributes($attributes,$condition='',$params=array())
{...
此方法从 CActiveRecord 到 Member、self、parent、$this、child 等的返回参数... 自动完成仅在“会员”时有效。但是这种方法适用于所有模型,而不仅仅是 Member 模型,所以这不是解决方案。
如果有人知道解决方案(最好不更改框架核心方法),我会很高兴。
【问题讨论】:
-
根据我的经验,您(很遗憾)目前无法做到这一点。有
@return self之类的注解,但它们不适用于继承。我已经开始明确注释所有变量,例如/** @var Member $member */。 -
感谢您的回复,@DCoder。我也在使用显式注释。但是通过代码和降低可读性等看起来很难看......如果我找到一个解决方案自动执行那将非常好。