From f801115e5e8d905ea83f5855ba9382d1b12c983a Mon Sep 17 00:00:00 2001 From: resurtm Date: Wed, 3 Jul 2013 11:26:43 +0600 Subject: [PATCH] Fixes #595. Add doc on changing model scenario. --- docs/guide/model.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/guide/model.md b/docs/guide/model.md index f0da8fa..b9d9812 100644 --- a/docs/guide/model.md +++ b/docs/guide/model.md @@ -114,6 +114,29 @@ We may do so by prefixing an exclamation character to the attribute name when de array('username', 'password', '!secret') ``` +Active model scenario could be set using one of the following ways: + +```php +class EmployeeController extends \yii\web\Controller +{ + public function actionCreate($id = null) + { + // first way + $employee = new Employee(array('scenario' => 'managementPanel')); + + // second way + $employee = new Employee; + $employee->scenario = 'managementPanel'; + + // third way + $employee = Employee::find()->where('id = :id', array(':id' => $id))->one(); + if ($employee !== null) { + $employee->setScenario('managementPanel'); + } + } +} +``` + Validation ----------