Код: Выделить всё
class Article extends CActiveRecord {
public function behaviors() {
return array(
'test' => array(
'class' => 'ext.TestBehavior.TestBehavior',
),
);
}
public function relations() {
return array(
'author' => array(self::BELONGS_TO, 'User', 'authorId'),
);
}
public function beforeFind($event) {
echo 'call Article::beforeFind';
parent::beforeFind($event);
}
}
Код: Выделить всё
class TestBehavior extends CActiveRecordBehavior {
public function beforeFind($event) {
echo 'call TestBehavior::beforeFind';
parent::beforeFind($event);
}
}
Код: Выделить всё
class ArticleController extends CController {
public function actionList() {
$criteria = new CDbCriteria;
$criteria->order = $this->getFieldName('createdTime') . ' DESC';
$withOption = array($this->getFieldName('author'));
// вот так выполняются оба метода beforeFind
$articles = Article::model()->findAll($criteria);
// а так уже не выполняется ни один
$articles = Article::model()->with($withOption)->findAll($criteria);
}
}