Commit db56384f by Carsten Brandt

improved documentation about loadDefaultValues()

issue #6126
parent 5cb93492
...@@ -322,8 +322,8 @@ if ($model->load(Yii::$app->request->post()) && $model->save()) { ...@@ -322,8 +322,8 @@ if ($model->load(Yii::$app->request->post()) && $model->save()) {
### Loading Default Values ### Loading Default Values
Your table columns may be defined with default values. Sometimes, you may want to pre-populate your Your table columns may be defined with default values. Sometimes, you may want to pre-populate your
Web form for an Active Record with these values. To do so, call the `loadDefaultValues()` method before Web form for an Active Record with these values. To do so, call the
rendering the form: [[yii\db\ActiveRecord::loadDefaultValues()|loadDefaultValues()]] method before rendering the form:
```php ```php
$customer = new Customer(); $customer = new Customer();
......
...@@ -100,8 +100,19 @@ class ActiveRecord extends BaseActiveRecord ...@@ -100,8 +100,19 @@ class ActiveRecord extends BaseActiveRecord
/** /**
* Loads default values from database table schema * Loads default values from database table schema
* *
* @param boolean $skipIfSet if existing value should be preserved * To enable loading defaults for every newly created record, you can add a call to this method to [[init()]]:
* @return static model instance *
* ```php
* public function init()
* {
* parent::init();
* $this->loadDefaultValues();
* }
* ```
*
* @param boolean $skipIfSet whether existing value should be preserved.
* This will only set defaults for attributes that are `null`.
* @return static the model instance itself.
*/ */
public function loadDefaultValues($skipIfSet = true) public function loadDefaultValues($skipIfSet = true)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment