Answer the question
In order to leave comments, you need to log in
Why doesn't beforeSafe work in the ActiveRecord model (Yii Framework)?
Most likely the reason is banal, but I do not know the answer.
beforeSafe itself
protected function beforeSafe()
{
if (preg_match('/(\d{2})\.(\d{2})\.(\d{4})/', $this->start))
{
$this->start = date('Y-m-d H:i:s', strtotime($this->start));
}
if (preg_match('/(\d{2})\.(\d{2})\.(\d{4})/', $this->finish))
{
$this->finish = date('Y-m-d H:i:s', strtotime($this->finish));
}
return parent::beforeSafe();
}
$order_model = Order::model()->getById($id);
public function getById($id)
{
$user = Order::model()->find('id = :id', array(':id' => $id));
return $user;
}
$order_model->save();
Answer the question
In order to leave comments, you need to log in
1) instead of beforeSafe - beforeSave
2) Why getById method when there is findByAttributes(array('id' => $id)) and findByPk($id)
Most likely the reason is banal, but I do not know the answer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question