From e990be9394d3c34e2a21999e543e17f132ce40e9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 5 Jan 2014 16:53:55 +0100 Subject: [PATCH] #1788 info about retaining the default scenario --- docs/guide/model.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/guide/model.md b/docs/guide/model.md index a02e1ad..643ce5f 100644 --- a/docs/guide/model.md +++ b/docs/guide/model.md @@ -112,6 +112,21 @@ class User extends \yii\db\ActiveRecord } ``` +If you want to keep the default scenario available besides your own scenarios, use inheritance to include it: +```php +class User extends \yii\db\ActiveRecord +{ + public function scenarios() + { + $scenarios = parent::scenarios(); + $scenarios['login'] = ['username', 'password']; + $scenarios['register'] = ['username', 'email', 'password']; + return $scenarios; + } +} +``` + + Sometimes, we want to mark an attribute as not safe for massive assignment (but we still want the attribute to be validated). We may do so by prefixing an exclamation character to the attribute name when declaring it in `scenarios()`. For example: