Home > PHP Framework > YII > body text

How to get the new data id in yii

angryTom
Release: 2020-02-17 09:40:48
Original
2707 people have browsed it

How to get the new data id in yii

How does yii get the newly added data id

//提交过来的数据
$post = Yii::$app->request->post();
//实例化对象
$model = new User();
$model->setAttributes($post);
if($model->validate()){
    $model->save();
}
//成功后获取该记录主键  id
var_dump($model->id);
Copy after login

If not obtained View models

Related article tutorial recommendations:yiiTutorial

How to get the new data id in yii

Just remove the defined primary key id.

The above is the detailed content of How to get the new data id in yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!