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()) {
### Loading Default Values
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
rendering the form:
Web form for an Active Record with these values. To do so, call the
[[yii\db\ActiveRecord::loadDefaultValues()|loadDefaultValues()]] method before rendering the form:
```php
$customer = new Customer();
......
......@@ -100,8 +100,19 @@ class ActiveRecord extends BaseActiveRecord
/**
* Loads default values from database table schema
*
* @param boolean $skipIfSet if existing value should be preserved
* @return static model instance
* To enable loading defaults for every newly created record, you can add a call to this method to [[init()]]:
*
* ```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)
{
......
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