public function actionUpdateprofile(){
$user = User::model()->findByPk($_POST['User']['user_id']);
$profile = Profile::model()->findByPk($_POST['User']['user_id']);
if(isset($_POST['User']) || isset($_POST['Profile'])){
$user->attributes = $_POST['User'];
$profile->attributes = $_POST['Profile'];
$user->save();
$profile->save();
}
}
我编写此代码是为了更新配置文件和用户表中的值。但它不起作用。
如果我发送 $_POST['Profile']['email'] = 'abc@gmail.com';
没有错误,但数据库仍然显示旧值。为什么?
我在那里做错了什么?
这是 $profile->attributes
的结果。电子邮件仍然具有旧值。
Array
(
[user_id] => 35
[lastname] => asd
[firstname] => asrtyr
[email] => xyz.gmail.com
[phoneno] => 123456
[prof_img] =>
[phoneno2] => 0
[agentKey] =>
[fb_id] =>
)
最佳答案
我建议你像下面这样添加错误报告
if(!$user->save()){
echo 'Error to save user model<br />';
var_dump($user->getErrors());
}
if(!$profile->save()){
echo 'Error to save profile model<br />';
var_dump($profile->getErrors());
}
关于php - yii 模型-> 保存不适用于更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26612018/