疯狂丨蜗牛
- 疯狂丨蜗牛 赞了说说不让男朋友在屋里抽烟有错吗?
- 疯狂丨蜗牛 2017-07-21 已签到连续签到1天,获得了5个金钱
$model = Zhongchou::findOne(['user_id => 1']);
$model->name = '张三';
if(!$model->save()) {
yii::$app->getSession()->setFlash('error', '抱歉,操作失败');
return $this->redirect(['index']);
}
@jiekii 那就只能查归查了 Zhongchou::find()->select([你需要的字段])->where(['user_id => 1'])->one();
修改 Zhongchou::updateAll(需要修改的数组,条件数组)- 疯狂丨蜗牛 回答了问题 find加select的话save无效
$model = Zhongchou::findOne(['user_id => 1']);
$model->name = '张三';
if(!$model->save()) {
yii::$app->getSession()->setFlash('error', '抱歉,操作失败');
return $this->redirect(['index']);
}