I have a model called Invoice.I have made necessary CRUD for Invoice model.The attributes for the Invoice model are as like Invoice Title, Invoice No, Invoice Issue Date, Description.Now I want that when a user will redirect to invoice create page,the input field for Invoice No should be automatically filled in the create page with last inserted id +1 and it should have prefix like INV:.So the input field for Invoice No should be like this INV:12.By this a user don’t need to fill the invoice no manually in increasing order.Here is the image for the create page.
I have a model called Invoice .I have made necessary CRUD for Invoice model
Share
First of all==>
This is not a good idea to store Invoice number dependent on table's unique idSo you should insert last invoice number’s number part+1 with text..
Now first get last invoice model then find its invoice number and populate the field..
In controller..
EDIT:
Reason why
Yii::app()->db->lastInsertId)cannot be used..First as I said in first place its not good to dependent invoice id from unique id of table..second what if somebody inserted sonething in someother table in between..third what if the db connection is closed and started in between..