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 also get the last inserted id of another model.
or
you can last inserted id in the same model
If
$model->id
wouldn't work then useYii::app()->db->getLastInsertId()
orgetPrimaryKey()
.In Yii2 last inserted id can be get using
not use
If your goal is to get the id that was assigned to the model that you just saved, then after you do
$model->save()
, simply do$model->id
to get it back.Reference Link : Here
You can get the last inserted ID like this:
See the Yii documentation for more information.