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
ae6c69fc
Commit
ae6c69fc
authored
Apr 05, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refacotring validators.
parent
86f947e9
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
162 additions
and
77 deletions
+162
-77
BooleanValidator.php
framework/validators/BooleanValidator.php
+14
-5
CaptchaValidator.php
framework/validators/CaptchaValidator.php
+14
-5
CompareValidator.php
framework/validators/CompareValidator.php
+1
-1
DateValidator.php
framework/validators/DateValidator.php
+16
-2
EmailValidator.php
framework/validators/EmailValidator.php
+16
-5
ExistValidator.php
framework/validators/ExistValidator.php
+14
-3
NumberValidator.php
framework/validators/NumberValidator.php
+1
-1
RangeValidator.php
framework/validators/RangeValidator.php
+9
-8
RegularExpressionValidator.php
framework/validators/RegularExpressionValidator.php
+7
-5
RequiredValidator.php
framework/validators/RequiredValidator.php
+17
-13
StringValidator.php
framework/validators/StringValidator.php
+20
-21
UniqueValidator.php
framework/validators/UniqueValidator.php
+16
-3
UrlValidator.php
framework/validators/UrlValidator.php
+17
-5
No files found.
framework/validators/BooleanValidator.php
View file @
ae6c69fc
...
...
@@ -36,6 +36,17 @@ class BooleanValidator extends Validator
public
$strict
=
false
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} must be either "{true}" or "{false}".'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param \yii\base\Model $object the object being validated
...
...
@@ -45,8 +56,7 @@ class BooleanValidator extends Validator
{
$value
=
$object
->
$attribute
;
if
(
!
$this
->
validateValue
(
$value
))
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
Yii
::
t
(
'yii|{attribute} must be either "{true}" or "{false}".'
);
$this
->
addError
(
$object
,
$attribute
,
$message
,
array
(
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
,
array
(
'{true}'
=>
$this
->
trueValue
,
'{false}'
=>
$this
->
falseValue
,
));
...
...
@@ -72,15 +82,14 @@ class BooleanValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
Yii
::
t
(
'yii|{attribute} must be either "{true}" or "{false}".'
);
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
'{true}'
=>
$this
->
trueValue
,
'{false}'
=>
$this
->
falseValue
,
));
return
"
if("
.
(
$this
->
allow
Empty
?
"$.trim(value)!='' && "
:
''
)
.
"value!="
.
json_encode
(
$this
->
trueValue
)
.
" && value!="
.
json_encode
(
$this
->
falseValue
)
.
") {
if("
.
(
$this
->
skipOn
Empty
?
"$.trim(value)!='' && "
:
''
)
.
"value!="
.
json_encode
(
$this
->
trueValue
)
.
" && value!="
.
json_encode
(
$this
->
falseValue
)
.
") {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
...
...
framework/validators/CaptchaValidator.php
View file @
ae6c69fc
...
...
@@ -31,6 +31,17 @@ class CaptchaValidator extends Validator
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|The verification code is incorrect.'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param \yii\base\Model $object the object being validated
...
...
@@ -40,8 +51,7 @@ class CaptchaValidator extends Validator
{
$value
=
$object
->
$attribute
;
if
(
!
$this
->
validateValue
(
$value
))
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
Yii
::
t
(
'yii|The verification code is incorrect.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
...
...
@@ -83,8 +93,7 @@ class CaptchaValidator extends Validator
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$captcha
=
$this
->
getCaptchaAction
();
$message
=
$this
->
message
!==
null
?
$this
->
message
:
\Yii
::
t
(
'yii|The verification code is incorrect.'
);
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
...
...
@@ -102,7 +111,7 @@ if(h != hash) {
}
"
;
if
(
$this
->
allow
Empty
)
{
if
(
$this
->
skipOn
Empty
)
{
$js
=
"
if($.trim(value)!='') {
$js
...
...
framework/validators/CompareValidator.php
View file @
ae6c69fc
...
...
@@ -223,7 +223,7 @@ class CompareValidator extends Validator
));
return
"
if ("
.
(
$this
->
allow
Empty
?
"$.trim(value)!='' && "
:
''
)
.
$condition
.
") {
if ("
.
(
$this
->
skipOn
Empty
?
"$.trim(value)!='' && "
:
''
)
.
$condition
.
") {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
...
...
framework/validators/DateValidator.php
View file @
ae6c69fc
...
...
@@ -32,6 +32,17 @@ class DateValidator extends Validator
public
$timestampAttribute
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|The format of {attribute} is invalid.'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param \yii\base\Model $object the object being validated
...
...
@@ -40,10 +51,13 @@ class DateValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
{
$value
=
$object
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
return
;
}
$date
=
DateTime
::
createFromFormat
(
$this
->
format
,
$value
);
if
(
$date
===
false
)
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
Yii
::
t
(
'yii|The format of {attribute} is invalid.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
elseif
(
$this
->
timestampAttribute
!==
false
)
{
$object
->
{
$this
->
timestampAttribute
}
=
$date
->
getTimestamp
();
}
...
...
framework/validators/EmailValidator.php
View file @
ae6c69fc
...
...
@@ -7,6 +7,8 @@
namespace
yii\validators
;
use
Yii
;
/**
* EmailValidator validates that the attribute value is a valid email address.
*
...
...
@@ -44,6 +46,17 @@ class EmailValidator extends Validator
public
$checkPort
=
false
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} is not a valid email address.'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param \yii\base\Model $object the object being validated
...
...
@@ -53,8 +66,7 @@ class EmailValidator extends Validator
{
$value
=
$object
->
$attribute
;
if
(
!
$this
->
validateValue
(
$value
))
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is not a valid email address.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
...
...
@@ -88,8 +100,7 @@ class EmailValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is not a valid email address.'
);
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
...
...
@@ -100,7 +111,7 @@ class EmailValidator extends Validator
}
return
"
if("
.
(
$this
->
allow
Empty
?
"$.trim(value)!='' && "
:
''
)
.
$condition
.
") {
if("
.
(
$this
->
skipOn
Empty
?
"$.trim(value)!='' && "
:
''
)
.
$condition
.
") {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
...
...
framework/validators/ExistValidator.php
View file @
ae6c69fc
...
...
@@ -37,6 +37,18 @@ class ExistValidator extends Validator
*/
public
$attributeName
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} is invalid.'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
...
...
@@ -49,7 +61,7 @@ class ExistValidator extends Validator
$value
=
$object
->
$attribute
;
if
(
is_array
(
$value
))
{
$this
->
addError
(
$object
,
$attribute
,
Yii
::
t
(
'yii|{attribute} is invalid.'
)
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
return
;
}
...
...
@@ -59,8 +71,7 @@ class ExistValidator extends Validator
$query
=
$className
::
find
();
$query
->
where
(
array
(
$attributeName
=>
$value
));
if
(
!
$query
->
exists
())
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
Yii
::
t
(
'yii|{attribute} "{value}" is invalid.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
...
...
framework/validators/NumberValidator.php
View file @
ae6c69fc
...
...
@@ -152,7 +152,7 @@ if(value>{$this->max}) {
"
;
}
if
(
$this
->
allow
Empty
)
{
if
(
$this
->
skipOn
Empty
)
{
$js
=
"
if(jQuery.trim(value)!='') {
$js
...
...
framework/validators/RangeValidator.php
View file @
ae6c69fc
...
...
@@ -6,6 +6,8 @@
*/
namespace
yii\validators
;
use
Yii
;
use
yii\base\InvalidConfigException
;
/**
...
...
@@ -44,6 +46,9 @@ class RangeValidator extends Validator
if
(
!
is_array
(
$this
->
range
))
{
throw
new
InvalidConfigException
(
'The "range" property must be set.'
);
}
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} is invalid.'
);
}
}
/**
...
...
@@ -55,11 +60,10 @@ class RangeValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
{
$value
=
$object
->
$attribute
;
$message
=
$this
->
message
!==
null
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is invalid.'
);
if
(
!
$this
->
not
&&
!
in_array
(
$value
,
$this
->
range
,
$this
->
strict
))
{
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$
this
->
message
);
}
elseif
(
$this
->
not
&&
in_array
(
$value
,
$this
->
range
,
$this
->
strict
))
{
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$
this
->
message
);
}
}
...
...
@@ -82,10 +86,7 @@ class RangeValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
if
((
$message
=
$this
->
message
)
===
null
)
{
$message
=
\Yii
::
t
(
'yii|{attribute} is invalid.'
);
}
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
...
...
@@ -97,7 +98,7 @@ class RangeValidator extends Validator
$range
=
json_encode
(
$range
);
return
"
if ("
.
(
$this
->
allow
Empty
?
"$.trim(value)!='' && "
:
''
)
.
(
$this
->
not
?
"$.inArray(value,
$range
)>=0"
:
"$.inArray(value,
$range
)<0"
)
.
") {
if ("
.
(
$this
->
skipOn
Empty
?
"$.trim(value)!='' && "
:
''
)
.
(
$this
->
not
?
"$.inArray(value,
$range
)>=0"
:
"$.inArray(value,
$range
)<0"
)
.
") {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
...
...
framework/validators/RegularExpressionValidator.php
View file @
ae6c69fc
...
...
@@ -7,6 +7,7 @@
namespace
yii\validators
;
use
Yii
;
use
yii\base\InvalidConfigException
;
/**
...
...
@@ -40,6 +41,9 @@ class RegularExpressionValidator extends Validator
if
(
$this
->
pattern
===
null
)
{
throw
new
InvalidConfigException
(
'The "pattern" property must be set.'
);
}
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} is invalid.'
);
}
}
/**
...
...
@@ -52,8 +56,7 @@ class RegularExpressionValidator extends Validator
{
$value
=
$object
->
$attribute
;
if
(
!
$this
->
validateValue
(
$value
))
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is invalid.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
...
...
@@ -78,8 +81,7 @@ class RegularExpressionValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is invalid.'
);
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
...
...
@@ -99,7 +101,7 @@ class RegularExpressionValidator extends Validator
}
return
"
if ("
.
(
$this
->
allow
Empty
?
"$.trim(value)!='' && "
:
''
)
.
(
$this
->
not
?
''
:
'!'
)
.
"value.match(
$pattern
)) {
if ("
.
(
$this
->
skipOn
Empty
?
"$.trim(value)!='' && "
:
''
)
.
(
$this
->
not
?
''
:
'!'
)
.
"value.match(
$pattern
)) {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
...
...
framework/validators/RequiredValidator.php
View file @
ae6c69fc
...
...
@@ -7,6 +7,8 @@
namespace
yii\validators
;
use
Yii
;
/**
* RequiredValidator validates that the specified attribute does not have null or empty value.
*
...
...
@@ -39,6 +41,17 @@ class RequiredValidator extends Validator
public
$strict
=
false
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
$this
->
requiredValue
===
null
?
Yii
::
t
(
'yii|{attribute} is invalid.'
)
:
Yii
::
t
(
'yii|{attribute} must be "{requiredValue}".'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param \yii\base\Model $object the object being validated
...
...
@@ -49,13 +62,11 @@ class RequiredValidator extends Validator
$value
=
$object
->
$attribute
;
if
(
$this
->
requiredValue
===
null
)
{
if
(
$this
->
strict
&&
$value
===
null
||
!
$this
->
strict
&&
$this
->
isEmpty
(
$value
,
true
))
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} cannot be blank.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
else
{
if
(
!
$this
->
strict
&&
$value
!=
$this
->
requiredValue
||
$this
->
strict
&&
$value
!==
$this
->
requiredValue
)
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} must be "{requiredValue}".'
);
$this
->
addError
(
$object
,
$attribute
,
$message
,
array
(
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
,
array
(
'{requiredValue}'
=>
$this
->
requiredValue
,
));
}
...
...
@@ -87,12 +98,8 @@ class RequiredValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
$this
->
message
;
if
(
$this
->
requiredValue
!==
null
)
{
if
(
$message
===
null
)
{
$message
=
\Yii
::
t
(
'yii|{attribute} must be "{requiredValue}".'
);
}
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
'{requiredValue}'
=>
$this
->
requiredValue
,
...
...
@@ -103,10 +110,7 @@ if (value != " . json_encode($this->requiredValue) . ") {
}
"
;
}
else
{
if
(
$message
===
null
)
{
$message
=
\Yii
::
t
(
'yii|{attribute} cannot be blank.'
);
}
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
...
...
framework/validators/StringValidator.php
View file @
ae6c69fc
...
...
@@ -63,6 +63,18 @@ class StringValidator extends Validator
if
(
$this
->
encoding
===
null
)
{
$this
->
encoding
=
Yii
::
$app
->
charset
;
}
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} must be a string.'
);
}
if
(
$this
->
min
!==
null
&&
$this
->
tooShort
===
null
)
{
$this
->
tooShort
=
Yii
::
t
(
'yii|{attribute} should contain at least {min} characters.'
);
}
if
(
$this
->
max
!==
null
&&
$this
->
tooLong
===
null
)
{
$this
->
tooLong
=
Yii
::
t
(
'yii|{attribute} should contain at most {max} characters.'
);
}
if
(
$this
->
is
!==
null
&&
$this
->
notEqual
===
null
)
{
$this
->
notEqual
=
Yii
::
t
(
'yii|{attribute} should contain {length} characters.'
);
}
}
/**
...
...
@@ -76,24 +88,20 @@ class StringValidator extends Validator
$value
=
$object
->
$attribute
;
if
(
!
is_string
(
$value
))
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
Yii
::
t
(
'yii|{attribute} must be a string.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
return
;
}
$length
=
mb_strlen
(
$value
,
$this
->
encoding
);
if
(
$this
->
min
!==
null
&&
$length
<
$this
->
min
)
{
$message
=
(
$this
->
tooShort
!==
null
)
?
$this
->
tooShort
:
Yii
::
t
(
'yii|{attribute} should contain at least {min} characters.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
,
array
(
'{min}'
=>
$this
->
min
));
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooShort
,
array
(
'{min}'
=>
$this
->
min
));
}
if
(
$this
->
max
!==
null
&&
$length
>
$this
->
max
)
{
$message
=
(
$this
->
tooLong
!==
null
)
?
$this
->
tooLong
:
Yii
::
t
(
'yii|{attribute} should contain at most {max} characters.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
,
array
(
'{max}'
=>
$this
->
max
));
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooLong
,
array
(
'{max}'
=>
$this
->
max
));
}
if
(
$this
->
is
!==
null
&&
$length
!==
$this
->
is
)
{
$message
=
(
$this
->
notEqual
!==
null
)
?
$this
->
notEqual
:
Yii
::
t
(
'yii|{attribute} should contain {length} characters.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
,
array
(
'{length}'
=>
$this
->
is
));
$this
->
addError
(
$object
,
$attribute
,
$this
->
notEqual
,
array
(
'{length}'
=>
$this
->
is
));
}
}
...
...
@@ -124,28 +132,19 @@ class StringValidator extends Validator
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$value
=
$object
->
$attribute
;
if
((
$notEqual
=
$this
->
notEqual
)
===
null
)
{
$notEqual
=
Yii
::
t
(
'yii|{attribute} should contain {length} characters.'
);
}
$notEqual
=
strtr
(
$notEqual
,
array
(
$notEqual
=
strtr
(
$this
->
notEqual
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{length}'
=>
$this
->
is
,
));
if
((
$tooShort
=
$this
->
tooShort
)
===
null
)
{
$tooShort
=
Yii
::
t
(
'yii|{attribute} should contain at least {min} characters.'
);
}
$tooShort
=
strtr
(
$tooShort
,
array
(
$tooShort
=
strtr
(
$this
->
tooShort
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{min}'
=>
$this
->
min
,
));
if
((
$tooLong
=
$this
->
tooLong
)
===
null
)
{
$tooLong
=
Yii
::
t
(
'yii|{attribute} should contain at most {max} characters.'
);
}
$tooLong
=
strtr
(
$tooLong
,
array
(
$tooLong
=
strtr
(
$this
->
tooLong
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{max}'
=>
$this
->
max
,
...
...
@@ -174,7 +173,7 @@ if(value.length!= {$this->is}) {
"
;
}
if
(
$this
->
allow
Empty
)
{
if
(
$this
->
skipOn
Empty
)
{
$js
=
"
if($.trim(value)!='') {
$js
...
...
framework/validators/UniqueValidator.php
View file @
ae6c69fc
...
...
@@ -6,6 +6,8 @@
*/
namespace
yii\validators
;
use
Yii
;
use
yii\base\InvalidConfigException
;
/**
...
...
@@ -31,6 +33,17 @@ class UniqueValidator extends Validator
public
$attributeName
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} "{value}" has already been taken.'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param \yii\db\ActiveRecord $object the object being validated
...
...
@@ -52,7 +65,7 @@ class UniqueValidator extends Validator
$table
=
$className
::
getTableSchema
();
if
((
$column
=
$table
->
getColumn
(
$attributeName
))
===
null
)
{
throw
new
InvalidConfigException
(
'Table "'
.
$table
->
name
.
'" does not have a column named "'
.
$attributeName
.
'"'
);
throw
new
InvalidConfigException
(
"Table '
{
$table
->
name
}
' does not have a column named '
$attributeName
'."
);
}
$query
=
$className
::
find
();
...
...
@@ -81,8 +94,7 @@ class UniqueValidator extends Validator
}
if
(
$exists
)
{
$message
=
$this
->
message
!==
null
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} "{value}" has already been taken.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
}
\ No newline at end of file
framework/validators/UrlValidator.php
View file @
ae6c69fc
...
...
@@ -7,6 +7,8 @@
namespace
yii\validators
;
use
Yii
;
/**
* UrlValidator validates that the attribute value is a valid http or https URL.
*
...
...
@@ -33,6 +35,18 @@ class UrlValidator extends Validator
**/
public
$defaultScheme
;
/**
* Initializes the validator.
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
message
===
null
)
{
$this
->
message
=
Yii
::
t
(
'yii|{attribute} is not a valid URL.'
);
}
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
...
...
@@ -47,8 +61,7 @@ class UrlValidator extends Validator
$object
->
$attribute
=
$this
->
defaultScheme
.
'://'
.
$value
;
}
}
else
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is not a valid URL.'
);
$this
->
addError
(
$object
,
$attribute
,
$message
);
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
}
...
...
@@ -87,8 +100,7 @@ class UrlValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
(
$this
->
message
!==
null
)
?
$this
->
message
:
\Yii
::
t
(
'yii|{attribute} is not a valid URL.'
);
$message
=
strtr
(
$message
,
array
(
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
...
...
@@ -113,7 +125,7 @@ $js
"
;
}
if
(
$this
->
allow
Empty
)
{
if
(
$this
->
skipOn
Empty
)
{
$js
=
"
if($.trim(value)!='') {
$js
...
...
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