$insert_id = $UserModel->attributes['id'];
$list = Yii::$app->db->createCommand('select * from user')->queryAll();
$sql = UserModel::find()->createCommand()->getRawSql();
$model->save
错误信息中的第一条public static function getModelError($model)
{
$errors = $model->getErrors(); //得到所有的错误信息
if (!is_array($errors)) {
return '';
}
$firstError = array_shift($errors);
if (!is_array($firstError)) {
return '';
}
return array_shift($firstError);
}
throw new \RuntimeException('保存失败:'.$model::getModelError($model));
Article::updateAllCounters(['view_count' => 1], ['id' => $id]);
// 实现的效果就是 view_count + 1,1根据你的需求可以是正数也可以是负数。
Article::updateAllCounters(['view_count' => 1], ['and', ['xxx' => 0, 'yyy' => 2], ['>', 'zzz', $time]);
开发常用知识点总结:
https://www.yiichina.com/topic/8274
了解更多:
https://www.yiichina.com/doc/guide/2.0
https://www.yiiframework.com/doc/guide/2.0/zh-cn
原文:https://www.cnblogs.com/yulongcode/p/11628348.html