在 Yii 中获取最后插入的值

2022-01-04 00:00:00 php mysql yii

我已经为表单做了一个模型.因为字段就像

id名姓描述created_at更新时间由...制作更新者

我已经为表单做了必要的 CRUD.现在我想为视图文件中最后插入的 id 获取一个额外的字段.那么如何获取该值?要获取该值,我应该在 CRUD 中进行任何必要的更改吗?任何帮助和建议将非常实用.

解决方案

你可以像这样获取最后插入的 ID:

Yii::app()->db->getLastInsertId();

有关详细信息,请参阅 Yii 文档.>

I have already made a model for form.In that the fields were like

id
firstname
lastname
description
created_at
updated_at
created_by
updated_by

I have made necessary CRUD for Form.Now I want to get one extra field for last inserted id in view file.So how to get that value?To get that value should I make any necessary changes in CRUD?Any help and suggestions will be highly appriciable.

解决方案

You can get the last inserted ID like this:

Yii::app()->db->getLastInsertId();

See the Yii documentation for more information.

相关文章