Difference between #3 and #4 of
Optimize Scenarios for yii2

Revision #4 has been created by AndroideLP on Oct 8, 2019, 1:44:40 PM with the memo:

AJUSTS ERROR TEXT
« previous (#3)

Changes

Title unchanged

Optimize Scenarios for yii2

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

model validation,model,validation rules

Content changed

[...]
```php
class MyModel extends \yii\db\ActiveRecord
{

const SCENARIOCR
IEATE = 'scenariocrieate';
const SCENARIOUPDATE = 'scenarioupdate';
[...]
return [
self::SCENARIOCR
IEATE => ['user_id', 'name', 'desc', 'published','date_create'],
self::SCENARIOUPDATE => ['user_id', 'name', 'desc', 'date_update'],
];
[...]
$allscenarios = $this->getCustomScenarios();
// published not required
$allscenarios[self::SCENARIOCR
IEATE] = array_diff($allscenarios[self::SCENARIOCRIEATE], ['published']);
return $allscenarios;
[...]
$allscenarios = $this->ModifyRequired();
return [
[$allscenarios[self::SCENARIOCR
IEATE], 'required', 'on' => self::SCENARIOCRIEATE],
[$allscenarios[self::SCENARIOUPDATE], 'required', 'on' => self::SCENARIOUPDATE],
[['user_id'], 'integer'],
[...]
$model = new MyModel;
$model->scenario = 'scenariocr
ieate';

if ($model->load(\Yii::$app->request->post())){

// force my columns
if($model->save()){
[...]
4 0
2 followers
Viewed: 43 554 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