Hi, learning Yii events I did not understood existence of one useless method. All Yii and third party
extension use both beforeSave and onBeforeSave as following:
abstract class CActiveRecord extends CModel
{
...
public function insert($attributes=null)
{
...
if($this->beforeSave())
...
}
protected function beforeSave()
{
if($this->hasEventHandler('onBeforeSave'))
{
$event=new CModelEvent($this);
$this->onBeforeSave($event);
return $event->isValid;
}
else
return true;
}
public function onBeforeSave($event)
{
$this->raiseEvent('onBeforeSave',$event);
}
}
So why do we need beforeSave here. One could write as following:
abstract class CActiveRecord extends CModel
{
...
public function insert($attributes=null)
{
...
if($this->onBeforeSave())
...
}
public function onBeforeSave($event)
{
if($this->hasEventHandler('onBeforeSave'))
{
$event=new CModelEvent($this);
$this->raiseEvent('onBeforeSave',$event);
return $event->isValid;
}
else
return true;
}
}