How to use delete(), insert() and save() methods in yii2?
Answer / Abhishek Verma
In Yii2, you can use the ActiveRecord's delete(), insert(), and save() methods for CRUD operations. Here's an example:
```php
// For deleting a record:
$model->delete();
// For creating (inserting) a new record:
$newModel = new ModelName;
$newModel->attribute1 = 'value1';
$newModel->save();
// For updating (saving) an existing record:
$existingModel = ModelName::findOne($id);
$existingModel->attribute1 = 'value1';
$existingModel->save();
```
| Is This Answer Correct ? | 0 Yes | 0 No |
How to generate crud code?
How to get current url in yii?
How can you include a javascript menu throught the site? Give steps
What is gii?
Can you remember what is directory structure when you downloaded yii?
How to use delete(), insert() and save() methods in yii2?
In yii, how to get ip address?
What is active record(ar) in yii?
List some database related functions in yii 2 framework?
How we can change the url for yii::app()->homeurl in yii2?
What is gii in yii 2.0 and why it is used?
What is active record (ar) in yii framework?