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
fe546cd2
Commit
fe546cd2
authored
Nov 07, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #5688: Added optional `$formName` to `Model::loadMultiple()` to support…
Fixes #5688: Added optional `$formName` to `Model::loadMultiple()` to support customizing form name directly
parent
6ada8737
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
12 deletions
+19
-12
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Model.php
framework/base/Model.php
+18
-12
No files found.
framework/CHANGELOG.md
View file @
fe546cd2
...
@@ -32,6 +32,7 @@ Yii Framework 2 Change Log
...
@@ -32,6 +32,7 @@ Yii Framework 2 Change Log
-
Enh #5600: Allow configuring debug panels in
`yii\debug\Module::panels`
as panel class name strings (qiangxue)
-
Enh #5600: Allow configuring debug panels in
`yii\debug\Module::panels`
as panel class name strings (qiangxue)
-
Enh #5613: Added
`--overwrite`
option to Gii console command to support overwriting all files (motin, qiangxue)
-
Enh #5613: Added
`--overwrite`
option to Gii console command to support overwriting all files (motin, qiangxue)
-
Enh #5646: Call
`yii\base\ErrorHandler::unregister()`
instead of
`restore_*_handlers`
directly (aivus)
-
Enh #5646: Call
`yii\base\ErrorHandler::unregister()`
instead of
`restore_*_handlers`
directly (aivus)
-
Enh #5688: Added optional
`$formName`
to
`Model::loadMultiple()`
to support customizing form name directly (qiangxue)
-
Enh #5735: Added
`yii\bootstrap\Tabs::renderTabContent`
to support manually rendering tab contents (RomeroMsk)
-
Enh #5735: Added
`yii\bootstrap\Tabs::renderTabContent`
to support manually rendering tab contents (RomeroMsk)
-
Enh #5770: Added more PHP error names for
`ErrorException`
(mongosoft)
-
Enh #5770: Added more PHP error names for
`ErrorException`
(mongosoft)
-
Enh #5806: Allow
`Html::encode()`
to be used when the application is not started (qiangxue)
-
Enh #5806: Allow
`Html::encode()`
to be used when the application is not started (qiangxue)
...
...
framework/base/Model.php
View file @
fe546cd2
...
@@ -763,25 +763,31 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
...
@@ -763,25 +763,31 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* @param array $models the models to be populated. Note that all models should have the same class.
* @param array $models the models to be populated. Note that all models should have the same class.
* @param array $data the data array. This is usually `$_POST` or `$_GET`, but can also be any valid array
* @param array $data the data array. This is usually `$_POST` or `$_GET`, but can also be any valid array
* supplied by end user.
* supplied by end user.
* @return boolean whether the model is successfully populated with some data.
* @param string $formName the form name to be used for loading the data into the models.
* If not set, it will use the [[formName()]] value of the first model in `$models`.
* @return boolean whether at least one of the models is successfully populated.
*/
*/
public
static
function
loadMultiple
(
$models
,
$data
)
public
static
function
loadMultiple
(
$models
,
$data
,
$formName
=
null
)
{
{
/* @var $model Model */
if
(
$formName
===
null
)
{
$model
=
reset
(
$models
);
/* @var $first Model */
if
(
$model
===
false
)
{
$first
=
reset
(
$models
);
return
false
;
if
(
$first
===
false
)
{
return
false
;
}
$formName
=
$first
->
formName
();
}
}
$success
=
false
;
$success
=
false
;
$scope
=
$model
->
formName
();
foreach
(
$models
as
$i
=>
$model
)
{
foreach
(
$models
as
$i
=>
$model
)
{
if
(
$scope
==
''
)
{
/* @var $model Model */
if
(
isset
(
$data
[
$i
]))
{
if
(
$formName
==
''
)
{
$model
->
setAttributes
(
$data
[
$i
]);
if
(
!
empty
(
$data
[
$i
]))
{
$model
->
load
(
$data
[
$i
],
''
);
$success
=
true
;
$success
=
true
;
}
}
}
elseif
(
isset
(
$data
[
$scop
e
][
$i
]))
{
}
elseif
(
!
empty
(
$data
[
$formNam
e
][
$i
]))
{
$model
->
setAttributes
(
$data
[
$scope
][
$i
]
);
$model
->
load
(
$data
[
$formName
][
$i
],
''
);
$success
=
true
;
$success
=
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