Пытаюсь реализовать Behavior:
<?php
class OldAttributesBehavior extends CActiveRecordBehavior
{
private $_oldattributes = array();
public function afterFind($event)
{
// Save old values
Yii::trace(get_class($this->getOwner()).'.'.get_class($this).'.afterFind()','app.components.behaviors');
$this->setOldAttributes($this->Owner->getAttributes());
}
public function getOldAttributes()
{
return $this->_oldattributes;
}
public function setOldAttributes($value)
{
$this->_oldattributes=$value;
}
}
Это нужно когда используеться акшин Update или Delete в нескольких модулях,
как уже не пробыл в моделе:
public function behaviors()
{
return array(
'OldAttributes' => array(
'class'=>'application.components.behaviors.OldAttributesBehavior',
'enabled'=>false,
),
);
}
а в контролере
$model=new User;
$model->enableBehavior('OldAttributes');
$this->_model=$model->findbyPk($_GET['id']);
или делал в контролере атач (в моделе ничего не прописывая):
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
$model=new User;
$model->attachBehavior('OldAttributes', new OldAttributesBehavior);
$this->_model=$model->findbyPk($_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
в конфиге прописывал импорт ‘import’=>array(…,‘application.components.behaviors.*’,…)
в логах в первом варианте app.components.behaviors User.OldAttributesBehavior.afterFind() всегда (при любом акшене), во втором варианте никогда, что не правильно делаю??