Difference between #1 and #2 of
Optimize Scenarios for yii2

Revision #2 has been created by AndroideLP on Apr 12, 2018, 1:23:10 PM with the memo:

update save error
« previous (#1) next (#3) »

Changes

Title unchanged

Optimize Scenarios for yii2

Category unchanged

Tutorials

Yii version changed

2.0

Tags changed

model, model validation, model,validation rules

Content changed

[...]
One way to avoid this disorder is to encapsulate the information defined for the scenarios and to have a single point of customization.

For this we need to create constants for each scenario, note: once you define a scenario, you will need to use scenarios for any database edition that uses this model.

**In model**

```php

class MyModel extends \yii\db\ActiveRecord
{
[...]
**In Controller**


```php

public function actionIndex()
{
[...]
if ($model->load(\Yii::$app->request->post())){
       // get all scenarios
 
        $allscenarios=$model->getCustomScenarios();
// force my columns if($model->save(true, $allscenarios[$this->scenario])){
//return true
}
}
}
```
[...]
4 0
2 followers
Viewed: 43 553 times
Version: 2.0
Category: Tutorials
Written by: AndroideLP
Last updated by: AndroideLP
Created on: Nov 8, 2016
Last updated: 5 years ago
Update Article

Revisions

View all history