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
518bc86b
Commit
518bc86b
authored
Jul 22, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
5f8a714e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
40 deletions
+22
-40
Model.php
framework/base/Model.php
+22
-40
No files found.
framework/base/Model.php
View file @
518bc86b
...
@@ -330,20 +330,20 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -330,20 +330,20 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
}
}
/**
/**
* Creates validator objects based on the
specification in {@link rules}
.
* Creates validator objects based on the
validation rules specified in [[rules]]
.
*
This method is mainly used internally
.
*
Unlike [[getValidators]], calling this method each time, it will return a new list of validators
.
* @return Vector validators
built based on {@link rules()}.
* @return Vector validators
*/
*/
public
function
createValidators
()
public
function
createValidators
()
{
{
$validators
=
new
Vector
;
$validators
=
new
Vector
;
foreach
(
$this
->
rules
()
as
$rule
)
{
foreach
(
$this
->
rules
()
as
$rule
)
{
if
(
isset
(
$rule
[
0
],
$rule
[
1
]))
{
// attributes, validator type
if
(
isset
(
$rule
[
0
],
$rule
[
1
]))
{
// attributes, validator type
$validators
->
add
(
\yii\validators\Validator
::
createValidator
(
$rule
[
1
],
$this
,
$rule
[
0
],
array_slice
(
$rule
,
2
)));
$validator
=
\yii\validators\Validator
::
createValidator
(
$rule
[
1
],
$this
,
$rule
[
0
],
array_slice
(
$rule
,
2
));
$validators
->
add
(
$validator
);
}
}
else
{
else
{
throw
new
Exception
(
spr
'{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.'
,
throw
new
Exception
(
'Invalid validation rule: a rule must specify both attribute names and validator type.'
);
array
(
'{class}'
=>
get_class
(
$this
))));
}
}
}
}
return
$validators
;
return
$validators
;
...
@@ -352,16 +352,17 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -352,16 +352,17 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
/**
/**
* Returns a value indicating whether the attribute is required.
* Returns a value indicating whether the attribute is required.
* This is determined by checking if the attribute is associated with a
* This is determined by checking if the attribute is associated with a
* {@link CRequiredValidator} validation rule in the current {@link scenario}.
* [[\yii\validators\RequiredValidator|required]] validation rule in the
* current {@link scenario}.
* @param string $attribute attribute name
* @param string $attribute attribute name
* @return boolean whether the attribute is required
* @return boolean whether the attribute is required
*/
*/
public
function
isAttributeRequired
(
$attribute
)
public
function
isAttributeRequired
(
$attribute
)
{
{
foreach
(
$this
->
getActiveValidators
(
$attribute
)
as
$validator
)
foreach
(
$this
->
getActiveValidators
(
$attribute
)
as
$validator
)
{
{
if
(
$validator
instanceof
\yii\validators\RequiredValidator
)
{
if
(
$validator
instanceof
CRequiredValidator
)
return
true
;
return
true
;
}
}
}
return
false
;
return
false
;
}
}
...
@@ -373,8 +374,13 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -373,8 +374,13 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
public
function
isAttributeSafe
(
$attribute
)
public
function
isAttributeSafe
(
$attribute
)
{
{
$attributes
=
$this
->
getSafeAttributeNames
();
$validators
=
$this
->
getActiveValidators
();
return
in_array
(
$attribute
,
$attributes
);
foreach
(
$validators
as
$validator
)
{
if
(
!
$validator
->
safe
)
{
return
false
;
}
}
return
$validators
!==
array
();
}
}
/**
/**
...
@@ -387,12 +393,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -387,12 +393,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
public
function
getAttributeLabel
(
$attribute
)
public
function
getAttributeLabel
(
$attribute
)
{
{
$labels
=
$this
->
attributeLabels
();
$labels
=
$this
->
attributeLabels
();
if
(
isset
(
$labels
[
$attribute
]))
{
return
isset
(
$labels
[
$attribute
])
?
$labels
[
$attribute
]
:
$this
->
generateAttributeLabel
(
$attribute
)
return
$labels
[
$attribute
];
}
else
{
return
$this
->
generateAttributeLabel
(
$attribute
);
}
}
}
/**
/**
...
@@ -402,12 +403,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -402,12 +403,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
public
function
hasErrors
(
$attribute
=
null
)
public
function
hasErrors
(
$attribute
=
null
)
{
{
if
(
$attribute
===
null
)
{
return
$attribute
===
null
?
!
empty
(
$this
->
_errors
)
:
isset
(
$this
->
_errors
[
$attribute
]);
return
!
empty
(
$this
->
_errors
);
}
else
{
return
isset
(
$this
->
_errors
[
$attribute
]);
}
}
}
/**
/**
...
@@ -559,21 +555,6 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -559,21 +555,6 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
}
}
/**
/**
* Sets the attributes to be null.
* @param array $names list of attributes to be set null. If this parameter is not given,
* all attributes as specified by [[attributeNames]] will have their values unset.
*/
public
function
unsetAttributes
(
$names
=
null
)
{
if
(
$names
===
null
)
{
$names
=
$this
->
attributeNames
();
}
foreach
(
$names
as
$name
)
{
$this
->
$name
=
null
;
}
}
/**
* This method is invoked when an unsafe attribute is being massively assigned.
* This method is invoked when an unsafe attribute is being massively assigned.
* The default implementation will log a warning message if YII_DEBUG is on.
* The default implementation will log a warning message if YII_DEBUG is on.
* It does nothing otherwise.
* It does nothing otherwise.
...
@@ -582,8 +563,9 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -582,8 +563,9 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
public
function
onUnsafeAttribute
(
$name
,
$value
)
public
function
onUnsafeAttribute
(
$name
,
$value
)
{
{
if
(
YII_DEBUG
)
if
(
YII_DEBUG
)
{
\Yii
::
warning
(
sprintf
(
'Failed to set unsafe attribute "%s" in "%s".'
,
$name
,
get_class
(
$this
));
\Yii
::
warning
(
sprintf
(
'Failed to set unsafe attribute "%s" in "%s".'
,
$name
,
get_class
(
$this
));
}
}
}
/**
/**
...
...
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