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
da786f65
Commit
da786f65
authored
Nov 09, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented new rules and safe attributes
parent
fbcf6776
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
20 deletions
+14
-20
Model.php
framework/base/Model.php
+0
-0
ActiveRecord.php
framework/db/ar/ActiveRecord.php
+4
-4
Validator.php
framework/validators/Validator.php
+9
-15
Sort.php
framework/web/Sort.php
+1
-1
No files found.
framework/base/Model.php
View file @
da786f65
This diff is collapsed.
Click to expand it.
framework/db/ar/ActiveRecord.php
View file @
da786f65
...
@@ -588,7 +588,7 @@ abstract class ActiveRecord extends Model
...
@@ -588,7 +588,7 @@ abstract class ActiveRecord extends Model
* This would return all column names of the table associated with this AR class.
* This would return all column names of the table associated with this AR class.
* @return array list of attribute names.
* @return array list of attribute names.
*/
*/
public
function
attribute
Name
s
()
public
function
attributes
()
{
{
return
array_keys
(
$this
->
getMetaData
()
->
table
->
columns
);
return
array_keys
(
$this
->
getMetaData
()
->
table
->
columns
);
}
}
...
@@ -633,7 +633,7 @@ abstract class ActiveRecord extends Model
...
@@ -633,7 +633,7 @@ abstract class ActiveRecord extends Model
public
function
getAttributes
(
$names
=
null
)
public
function
getAttributes
(
$names
=
null
)
{
{
if
(
$names
===
null
)
{
if
(
$names
===
null
)
{
$names
=
$this
->
attribute
Name
s
();
$names
=
$this
->
attributes
();
}
}
$values
=
array
();
$values
=
array
();
foreach
(
$names
as
$name
)
{
foreach
(
$names
as
$name
)
{
...
@@ -645,7 +645,7 @@ abstract class ActiveRecord extends Model
...
@@ -645,7 +645,7 @@ abstract class ActiveRecord extends Model
public
function
getChangedAttributes
(
$names
=
null
)
public
function
getChangedAttributes
(
$names
=
null
)
{
{
if
(
$names
===
null
)
{
if
(
$names
===
null
)
{
$names
=
$this
->
attribute
Name
s
();
$names
=
$this
->
attributes
();
}
}
$names
=
array_flip
(
$names
);
$names
=
array_flip
(
$names
);
$attributes
=
array
();
$attributes
=
array
();
...
@@ -931,7 +931,7 @@ abstract class ActiveRecord extends Model
...
@@ -931,7 +931,7 @@ abstract class ActiveRecord extends Model
return
false
;
return
false
;
}
}
if
(
$attributes
===
null
)
{
if
(
$attributes
===
null
)
{
foreach
(
$this
->
attribute
Name
s
()
as
$name
)
{
foreach
(
$this
->
attributes
()
as
$name
)
{
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
];
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
];
}
}
$this
->
_oldAttributes
=
$this
->
_attributes
;
$this
->
_oldAttributes
=
$this
->
_attributes
;
...
...
framework/validators/Validator.php
View file @
da786f65
...
@@ -42,8 +42,6 @@ namespace yii\validators;
...
@@ -42,8 +42,6 @@ namespace yii\validators;
* - `captcha`: [[CaptchaValidator]]
* - `captcha`: [[CaptchaValidator]]
* - `default`: [[DefaultValueValidator]]
* - `default`: [[DefaultValueValidator]]
* - `exist`: [[ExistValidator]]
* - `exist`: [[ExistValidator]]
* - `safe`: [[SafeValidator]]
* - `unsafe`: [[UnsafeValidator]]
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
...
@@ -58,8 +56,6 @@ abstract class Validator extends \yii\base\Component
...
@@ -58,8 +56,6 @@ abstract class Validator extends \yii\base\Component
'match'
=>
'\yii\validators\RegularExpressionValidator'
,
'match'
=>
'\yii\validators\RegularExpressionValidator'
,
'email'
=>
'\yii\validators\EmailValidator'
,
'email'
=>
'\yii\validators\EmailValidator'
,
'url'
=>
'\yii\validators\UrlValidator'
,
'url'
=>
'\yii\validators\UrlValidator'
,
'safe'
=>
'\yii\validators\SafeValidator'
,
'unsafe'
=>
'\yii\validators\UnsafeValidator'
,
'filter'
=>
'\yii\validators\FilterValidator'
,
'filter'
=>
'\yii\validators\FilterValidator'
,
'captcha'
=>
'\yii\validators\CaptchaValidator'
,
'captcha'
=>
'\yii\validators\CaptchaValidator'
,
'default'
=>
'\yii\validators\DefaultValueValidator'
,
'default'
=>
'\yii\validators\DefaultValueValidator'
,
...
@@ -103,11 +99,6 @@ abstract class Validator extends \yii\base\Component
...
@@ -103,11 +99,6 @@ abstract class Validator extends \yii\base\Component
*/
*/
public
$skipOnError
=
true
;
public
$skipOnError
=
true
;
/**
/**
* @var boolean whether attributes listed with this validator should be considered safe for
* massive assignment. Defaults to true.
*/
public
$safe
=
true
;
/**
* @var boolean whether to enable client-side validation. Defaults to true.
* @var boolean whether to enable client-side validation. Defaults to true.
* Please refer to [[\yii\web\ActiveForm::enableClientValidation]] for more details about
* Please refer to [[\yii\web\ActiveForm::enableClientValidation]] for more details about
* client-side validation.
* client-side validation.
...
@@ -187,8 +178,10 @@ abstract class Validator extends \yii\base\Component
...
@@ -187,8 +178,10 @@ abstract class Validator extends \yii\base\Component
/**
/**
* Validates the specified object.
* Validates the specified object.
* @param \yii\base\Model $object the data object being validated
* @param \yii\base\Model $object the data object being validated
* @param array $attributes the list of attributes to be validated. Defaults to null,
* @param array|null $attributes the list of attributes to be validated.
* meaning every attribute listed in [[attributes]] will be validated.
* Note that if an attribute is not associated with the validator,
* it will be ignored.
* If this parameter is null, every attribute listed in [[attributes]] will be validated.
*/
*/
public
function
validate
(
$object
,
$attributes
=
null
)
public
function
validate
(
$object
,
$attributes
=
null
)
{
{
...
@@ -228,10 +221,11 @@ abstract class Validator extends \yii\base\Component
...
@@ -228,10 +221,11 @@ abstract class Validator extends \yii\base\Component
}
}
/**
/**
* Returns a value indicating whether the validator applies to the specified scenario.
* Returns a value indicating whether the validator is active for the given scenario and attribute.
* A validator applies to a scenario as long as any of the following conditions is met:
*
* A validator is active if
*
*
* - the validator's `on` property is empty
* - the validator's `on` property is empty
, or
* - the validator's `on` property contains the specified scenario
* - the validator's `on` property contains the specified scenario
*
*
* @param string $scenario scenario name
* @param string $scenario scenario name
...
@@ -239,7 +233,7 @@ abstract class Validator extends \yii\base\Component
...
@@ -239,7 +233,7 @@ abstract class Validator extends \yii\base\Component
* the method will also check if the attribute appears in [[attributes]].
* the method will also check if the attribute appears in [[attributes]].
* @return boolean whether the validator applies to the specified scenario.
* @return boolean whether the validator applies to the specified scenario.
*/
*/
public
function
applyTo
(
$scenario
,
$attribute
=
null
)
public
function
isActive
(
$scenario
,
$attribute
=
null
)
{
{
$applies
=
!
isset
(
$this
->
except
[
$scenario
])
&&
(
empty
(
$this
->
on
)
||
isset
(
$this
->
on
[
$scenario
]));
$applies
=
!
isset
(
$this
->
except
[
$scenario
])
&&
(
empty
(
$this
->
on
)
||
isset
(
$this
->
on
[
$scenario
]));
return
$attribute
===
null
?
$applies
:
$applies
&&
in_array
(
$attribute
,
$this
->
attributes
,
true
);
return
$attribute
===
null
?
$applies
:
$applies
&&
in_array
(
$attribute
,
$this
->
attributes
,
true
);
...
...
framework/web/Sort.php
View file @
da786f65
...
@@ -429,7 +429,7 @@ class CSort extends CComponent
...
@@ -429,7 +429,7 @@ class CSort extends CComponent
$attributes
=
$this
->
attributes
;
$attributes
=
$this
->
attributes
;
}
else
{
}
else
{
if
(
$this
->
modelClass
!==
null
)
{
if
(
$this
->
modelClass
!==
null
)
{
$attributes
=
CActiveRecord
::
model
(
$this
->
modelClass
)
->
attribute
Name
s
();
$attributes
=
CActiveRecord
::
model
(
$this
->
modelClass
)
->
attributes
();
}
else
{
}
else
{
return
false
;
return
false
;
}
}
...
...
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