Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
db56384f
Commit
db56384f
authored
Nov 20, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved documentation about loadDefaultValues()
issue #6126
parent
5cb93492
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
db-active-record.md
docs/guide/db-active-record.md
+2
-2
ActiveRecord.php
framework/db/ActiveRecord.php
+13
-2
No files found.
docs/guide/db-active-record.md
View file @
db56384f
...
...
@@ -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
();
...
...
framework/db/ActiveRecord.php
View file @
db56384f
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment