Mam taką funkcję w modelu formularza od zarządzania profilem:
public function update($id)
{
$u = Users::model()->findByPk($id);
$u->firstname = $this->firstname;
$u->lastname = $this->lastname;
$u->address = $this->address;
$u->postcode = $this->postcode;
$u->city = $this->city;
$u->phone = $this->phone;
if(!empty($this->email))
$u->email = $this->email;
if(!empty($this->password))
{
$salt = $this->generateSalt();
$u->password = $u->encodePassword($this->email, $this->password, $salt);
$u->salt = $salt;
}
$u->save();
}
Mimo to, że wszystkie dane są wysyłane poprawne (sprawdzałem CVarDebugger’em, zarówno $this jak i $u po wprowadzeniu danych), a save() w modelu i validate() w kontrolerze nie wyrzucają żadnych błędów to rekord nie chce się zaaktualizować.
Gdzie jest błąd?
Funkcja w kontrolerze wygląda w taki sposób:
public function actionEdit()
{
if(Yii::app()->user->isGuest)
throw new CHttpException('403');
$model = new FormProfile('edit');
if (isset($_POST['FormProfile'])) {
$model->attributes = $_POST['FormProfile'];
if ( $model->validate() ) {
$model->update(Yii::app()->user->id);
}
}
else
{
$model->attributes = Users::model()->findByPk(Yii::app()->user->id)->attributes;
$model->password = NULL;
}
$this->render('edit',array(
'model' => $model,
));
}