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
7aae667e
Commit
7aae667e
authored
Dec 26, 2014
by
pana1990
Committed by
Alexander Makarov
Dec 26, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #6618: Added Model::addErrors()
parent
e91b252b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
0 deletions
+64
-0
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Model.php
framework/base/Model.php
+21
-0
ModelTest.php
tests/unit/framework/base/ModelTest.php
+42
-0
No files found.
framework/CHANGELOG.md
View file @
7aae667e
...
@@ -13,6 +13,7 @@ Yii Framework 2 Change Log
...
@@ -13,6 +13,7 @@ Yii Framework 2 Change Log
-
Enh #6434: Added
`yii\behaviors\SluggableBehavior::immutable`
to support keeping the generated slug unchanged (trntv)
-
Enh #6434: Added
`yii\behaviors\SluggableBehavior::immutable`
to support keeping the generated slug unchanged (trntv)
-
Enh #6467:
`ActiveForm`
will scroll to the nearest visible element when the first error input is hidden (newartix)
-
Enh #6467:
`ActiveForm`
will scroll to the nearest visible element when the first error input is hidden (newartix)
-
Enh #6488: Support changing
`yii\base\Theme::basePath`
during runtime (qiangxue)
-
Enh #6488: Support changing
`yii\base\Theme::basePath`
during runtime (qiangxue)
-
Enh #6618: Added Model::addErrors() (slavcodev, pana1990)
-
Chg #6427: In case of invalid route web application now throws exception with "Page not found" instead of "Invalid Route" (cebe, samdark)
-
Chg #6427: In case of invalid route web application now throws exception with "Page not found" instead of "Invalid Route" (cebe, samdark)
-
Chg #6641: removed zero padding from ETag strings (DaSourcerer)
-
Chg #6641: removed zero padding from ETag strings (DaSourcerer)
...
...
framework/base/Model.php
View file @
7aae667e
...
@@ -575,6 +575,27 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
...
@@ -575,6 +575,27 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
}
}
/**
/**
* Adds a list of errors.
* @param array $items a list of errors. The array keys must be attribute names.
* The array values should be error messages. If an attribute has multiple errors,
* these errors must be given in terms of an array.
* You may use the result of [[getErrors()]] as the value for this parameter.
* @since 2.0.2
*/
public
function
addErrors
(
array
$items
)
{
foreach
(
$items
as
$attribute
=>
$errors
)
{
if
(
is_array
(
$errors
))
{
foreach
(
$errors
as
$error
)
{
$this
->
addError
(
$attribute
,
$error
);
}
}
else
{
$this
->
addError
(
$attribute
,
$errors
);
}
}
}
/**
* Removes errors for all attributes or a single attribute.
* Removes errors for all attributes or a single attribute.
* @param string $attribute attribute name. Use null to remove errors for all attribute.
* @param string $attribute attribute name. Use null to remove errors for all attribute.
*/
*/
...
...
tests/unit/framework/base/ModelTest.php
View file @
7aae667e
...
@@ -170,6 +170,48 @@ class ModelTest extends TestCase
...
@@ -170,6 +170,48 @@ class ModelTest extends TestCase
$this
->
assertFalse
(
$speaker
->
hasErrors
());
$this
->
assertFalse
(
$speaker
->
hasErrors
());
}
}
public
function
testAddErrors
()
{
$singer
=
new
Singer
();
$errors
=
[
'firstName'
=>
[
'Something is wrong!'
]];
$singer
->
addErrors
(
$errors
);
$this
->
assertEquals
(
$singer
->
getErrors
(),
$errors
);
$singer
->
clearErrors
();
$singer
->
addErrors
([
'firstName'
=>
'Something is wrong!'
]);
$this
->
assertEquals
(
$singer
->
getErrors
(),
[
'firstName'
=>
[
'Something is wrong!'
]]);
$singer
->
clearErrors
();
$errors
=
[
'firstName'
=>
[
'Something is wrong!'
,
'Totally wrong!'
]];
$singer
->
addErrors
(
$errors
);
$this
->
assertEquals
(
$singer
->
getErrors
(),
$errors
);
$singer
->
clearErrors
();
$errors
=
[
'firstName'
=>
[
'Something is wrong!'
],
'lastName'
=>
[
'Another one!'
]
];
$singer
->
addErrors
(
$errors
);
$this
->
assertEquals
(
$singer
->
getErrors
(),
$errors
);
$singer
->
clearErrors
();
$errors
=
[
'firstName'
=>
[
'Something is wrong!'
,
'Totally wrong!'
],
'lastName'
=>
[
'Another one!'
]
];
$singer
->
addErrors
(
$errors
);
$this
->
assertEquals
(
$singer
->
getErrors
(),
$errors
);
$singer
->
clearErrors
();
$errors
=
[
'firstName'
=>
[
'Something is wrong!'
,
'Totally wrong!'
],
'lastName'
=>
[
'Another one!'
,
'Totally wrong!'
]
];
$singer
->
addErrors
(
$errors
);
$this
->
assertEquals
(
$singer
->
getErrors
(),
$errors
);
}
public
function
testArraySyntax
()
public
function
testArraySyntax
()
{
{
$speaker
=
new
Speaker
();
$speaker
=
new
Speaker
();
...
...
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