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 |
What is cactiverecord in yii framework ?
What is cmodel class in yii2?
How to generate crud code?
What is cformmodel in yii framework ?
What are the core components of yii2 framework?
How to use session in yii?
What are the core helper classes in yii framework?
What are components in yii 2?
What is the naming convention in yii framework? Explain
What is widgets in yii? How we can use it?
How does yii compare with other frameworks?
What is required properties in yii application? Why?