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
76b153a3
Commit
76b153a3
authored
Jan 20, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed event doc.
parent
edc48dc9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
44 deletions
+51
-44
ActiveRecord.md
docs/api/db/ActiveRecord.md
+9
-9
Application.php
framework/base/Application.php
+2
-2
Model.php
framework/base/Model.php
+19
-14
ActiveRecord.php
framework/db/ActiveRecord.php
+15
-13
Connection.php
framework/db/Connection.php
+1
-1
Logger.php
framework/logging/Logger.php
+1
-1
Router.php
framework/logging/Router.php
+4
-4
No files found.
docs/api/db/ActiveRecord.md
View file @
76b153a3
...
@@ -375,27 +375,27 @@ method overriding and event handling mechanisms.
...
@@ -375,27 +375,27 @@ method overriding and event handling mechanisms.
When instantiating a new ActiveRecord instance, we will have the following life cycles:
When instantiating a new ActiveRecord instance, we will have the following life cycles:
1.
constructor
1.
constructor
2.
[
[init()
]
]: will trigger an
[
[
init
]
] event
2.
[
[init()
]
]: will trigger an
[
[
EVENT_INIT
]
] event
When getting an ActiveRecord instance through the
[
[find()
]
] method, we will have the following life cycles:
When getting an ActiveRecord instance through the
[
[find()
]
] method, we will have the following life cycles:
1.
constructor
1.
constructor
2.
[
[init()
]
]: will trigger an
[
[
init
]
] event
2.
[
[init()
]
]: will trigger an
[
[
EVENT_INIT
]
] event
3.
[
[afterFind()
]
]: will trigger an
[
[
afterFind
]
] event
3.
[
[afterFind()
]
]: will trigger an
[
[
EVENT_AFTER_FIND
]
] event
When calling
[
[save()
]
] to insert or update an ActiveRecord, we will have the following life cycles:
When calling
[
[save()
]
] to insert or update an ActiveRecord, we will have the following life cycles:
1.
[
[beforeValidate()
]
]: will trigger an
[
[
beforeValidate
]
] event
1.
[
[beforeValidate()
]
]: will trigger an
[
[
EVENT_BEFORE_VALIDATE
]
] event
2.
[
[beforeSave()
]
]: will trigger an
[
[
beforeSave
]
] event
2.
[
[beforeSave()
]
]: will trigger an
[
[
EVENT_BEFORE_INSERT
]
] or
[
[EVENT_BEFORE_UPDATE
]
] event
3.
perform the actual data insertion or updating
3.
perform the actual data insertion or updating
4.
[
[afterSave()
]
]: will trigger an
[
[
afterSave
]
] event
4.
[
[afterSave()
]
]: will trigger an
[
[
EVENT_AFTER_INSERT
]
] or
[
[EVENT_AFTER_UPDATE
]
] event
5.
[
[afterValidate()
]
]: will trigger an
[
[
afterValidate
]
] event
5.
[
[afterValidate()
]
]: will trigger an
[
[
EVENT_AFTER_VALIDATE
]
] event
Finally when calling
[
[delete()
]
] to delete an ActiveRecord, we will have the following life cycles:
Finally when calling
[
[delete()
]
] to delete an ActiveRecord, we will have the following life cycles:
1.
[
[beforeDelete()
]
]: will trigger an
[
[
beforeDelete
]
] event
1.
[
[beforeDelete()
]
]: will trigger an
[
[
EVENT_BEFORE_DELETE
]
] event
2.
perform the actual data deletion
2.
perform the actual data deletion
3.
[
[afterDelete()
]
]: will trigger an
[
[
afterDelete
]
] event
3.
[
[afterDelete()
]
]: will trigger an
[
[
EVENT_AFTER_DELETE
]
] event
### Scopes
### Scopes
...
...
framework/base/Application.php
View file @
76b153a3
...
@@ -176,7 +176,7 @@ class Application extends Module
...
@@ -176,7 +176,7 @@ class Application extends Module
}
}
/**
/**
* Raises the [[
beforeRequest
]] event right BEFORE the application processes the request.
* Raises the [[
EVENT_BEFORE_REQUEST
]] event right BEFORE the application processes the request.
*/
*/
public
function
beforeRequest
()
public
function
beforeRequest
()
{
{
...
@@ -184,7 +184,7 @@ class Application extends Module
...
@@ -184,7 +184,7 @@ class Application extends Module
}
}
/**
/**
* Raises the [[
afterRequest
]] event right AFTER the application processes the request.
* Raises the [[
EVENT_AFTER_REQUEST
]] event right AFTER the application processes the request.
*/
*/
public
function
afterRequest
()
public
function
afterRequest
()
{
{
...
...
framework/base/Model.php
View file @
76b153a3
...
@@ -26,8 +26,8 @@ use yii\validators\RequiredValidator;
...
@@ -26,8 +26,8 @@ use yii\validators\RequiredValidator;
*
*
* Model also raises the following events when performing data validation:
* Model also raises the following events when performing data validation:
*
*
* - [[
beforeValidate
]]: an event raised at the beginning of [[validate()]]
* - [[
EVENT_BEFORE_VALIDATE
]]: an event raised at the beginning of [[validate()]]
* - [[
afterValidate
]]: an event raised at the end of [[validate()]]
* - [[
EVENT_AFTER_VALIDATE
]]: an event raised at the end of [[validate()]]
*
*
* You may directly use Model to store model data, or extend it with customization.
* You may directly use Model to store model data, or extend it with customization.
* You may also customize Model by attaching [[ModelBehavior|model behaviors]].
* You may also customize Model by attaching [[ModelBehavior|model behaviors]].
...
@@ -53,9 +53,17 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -53,9 +53,17 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
const
EVENT_AFTER_VALIDATE
=
'afterValidate'
;
const
EVENT_AFTER_VALIDATE
=
'afterValidate'
;
private
static
$_attributes
=
array
();
// class name => array of attribute names
/**
private
$_errors
;
// attribute name => array of errors
* @var array validation errors (attribute name => array of errors)
private
$_validators
;
// Vector of validators
*/
private
$_errors
;
/**
* @var Vector vector of validators
*/
private
$_validators
;
/**
* @var string current scenario
*/
private
$_scenario
=
'default'
;
private
$_scenario
=
'default'
;
/**
/**
...
@@ -85,15 +93,15 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -85,15 +93,15 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
* - additional name-value pairs can be specified to initialize the corresponding validator properties.
* - additional name-value pairs can be specified to initialize the corresponding validator properties.
* Please refer to individual validator class API for possible properties.
* Please refer to individual validator class API for possible properties.
*
*
* A validator can be either an object of a class extending [[
\yii\validators\Validator]],
* A validator can be either an object of a class extending [[
Validator]], or a model class method
*
or a model class method
(called *inline validator*) that has the following signature:
* (called *inline validator*) that has the following signature:
*
*
* ~~~
* ~~~
* // $params refers to validation parameters given in the rule
* // $params refers to validation parameters given in the rule
* function validatorName($attribute, $params)
* function validatorName($attribute, $params)
* ~~~
* ~~~
*
*
* Yii also provides a set of [[
\yii\validators\
Validator::builtInValidators|built-in validators]].
* Yii also provides a set of [[Validator::builtInValidators|built-in validators]].
* They each has an alias name which can be used when specifying a validation rule.
* They each has an alias name which can be used when specifying a validation rule.
*
*
* Below are some examples:
* Below are some examples:
...
@@ -151,10 +159,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -151,10 +159,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
{
{
$attributes
=
array
();
$attributes
=
array
();
foreach
(
$this
->
getActiveValidators
()
as
$validator
)
{
foreach
(
$this
->
getActiveValidators
()
as
$validator
)
{
if
(
$validator
->
isActive
(
'default'
))
{
foreach
(
$validator
->
attributes
as
$name
)
{
foreach
(
$validator
->
attributes
as
$name
)
{
$attributes
[
$name
]
=
true
;
$attributes
[
$name
]
=
true
;
}
}
}
}
}
return
array
(
return
array
(
'default'
=>
array_keys
(
$attributes
),
'default'
=>
array_keys
(
$attributes
),
);
);
...
@@ -168,11 +178,6 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -168,11 +178,6 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
public
function
attributes
()
public
function
attributes
()
{
{
$className
=
get_class
(
$this
);
if
(
isset
(
self
::
$_attributes
[
$className
]))
{
return
self
::
$_attributes
[
$className
];
}
$class
=
new
\ReflectionClass
(
$this
);
$class
=
new
\ReflectionClass
(
$this
);
$names
=
array
();
$names
=
array
();
foreach
(
$class
->
getProperties
(
\ReflectionProperty
::
IS_PUBLIC
)
as
$property
)
{
foreach
(
$class
->
getProperties
(
\ReflectionProperty
::
IS_PUBLIC
)
as
$property
)
{
...
@@ -181,7 +186,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -181,7 +186,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
$names
[]
=
$name
;
$names
[]
=
$name
;
}
}
}
}
return
self
::
$_attributes
[
$className
]
=
$names
;
return
$names
;
}
}
/**
/**
...
...
framework/db/ActiveRecord.php
View file @
76b153a3
...
@@ -608,8 +608,9 @@ class ActiveRecord extends Model
...
@@ -608,8 +608,9 @@ class ActiveRecord extends Model
* 4. call [[afterSave()]];
* 4. call [[afterSave()]];
* 5. call [[afterValidate()]] when `$runValidation` is true.
* 5. call [[afterValidate()]] when `$runValidation` is true.
*
*
* In the above step 1, 2, 4 and 5, events named `beforeValidate`, `beforeInsert`,
* In the above step 1, 2, 4 and 5, events [[EVENT_BEFORE_VALIDATE]],
* `afterInsert` and `afterValidate` will be raised by the corresponding methods.
* [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]]
* will be raised by the corresponding methods.
*
*
* Only the [[changedAttributes|changed attribute values]] will be inserted into database.
* Only the [[changedAttributes|changed attribute values]] will be inserted into database.
*
*
...
@@ -678,8 +679,9 @@ class ActiveRecord extends Model
...
@@ -678,8 +679,9 @@ class ActiveRecord extends Model
* 4. call [[afterSave()]];
* 4. call [[afterSave()]];
* 5. call [[afterValidate()]] when `$runValidation` is true.
* 5. call [[afterValidate()]] when `$runValidation` is true.
*
*
* In the above step 1, 2, 4 and 5, events named `beforeValidate`, `beforeUpdate`,
* In the above step 1, 2, 4 and 5, events [[EVENT_BEFORE_VALIDATE]],
* `afterUpdate` and `afterValidate` will be raised by the corresponding methods.
* [[EVENT_BEFORE_UPDATE]], [[EVENT_AFTER_UPDATE]] and [[EVENT_AFTER_VALIDATE]]
* will be raised by the corresponding methods.
*
*
* Only the [[changedAttributes|changed attribute values]] will be saved into database.
* Only the [[changedAttributes|changed attribute values]] will be saved into database.
*
*
...
@@ -760,7 +762,7 @@ class ActiveRecord extends Model
...
@@ -760,7 +762,7 @@ class ActiveRecord extends Model
* 2. delete the record from the database;
* 2. delete the record from the database;
* 3. call [[afterDelete()]].
* 3. call [[afterDelete()]].
*
*
* In the above step 1 and 3, events named
`beforeDelete` and `afterDelete`
* In the above step 1 and 3, events named
[[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]]
* will be raised by the corresponding methods.
* will be raised by the corresponding methods.
*
*
* @return boolean whether the deletion is successful.
* @return boolean whether the deletion is successful.
...
@@ -791,7 +793,7 @@ class ActiveRecord extends Model
...
@@ -791,7 +793,7 @@ class ActiveRecord extends Model
/**
/**
* Initializes the object.
* Initializes the object.
* This method is called at the end of the constructor.
* This method is called at the end of the constructor.
* The default implementation will trigger an [[
afterInsert
]] event.
* The default implementation will trigger an [[
EVENT_INIT
]] event.
* If you override this method, make sure you call the parent implementation at the end
* If you override this method, make sure you call the parent implementation at the end
* to ensure triggering of the event.
* to ensure triggering of the event.
*/
*/
...
@@ -803,7 +805,7 @@ class ActiveRecord extends Model
...
@@ -803,7 +805,7 @@ class ActiveRecord extends Model
/**
/**
* This method is called when the AR object is created and populated with the query result.
* This method is called when the AR object is created and populated with the query result.
* The default implementation will trigger an [[
afterFind
]] event.
* The default implementation will trigger an [[
EVENT_AFTER_FIND
]] event.
* When overriding this method, make sure you call the parent implementation to ensure the
* When overriding this method, make sure you call the parent implementation to ensure the
* event is triggered.
* event is triggered.
*/
*/
...
@@ -824,8 +826,8 @@ class ActiveRecord extends Model
...
@@ -824,8 +826,8 @@ class ActiveRecord extends Model
/**
/**
* This method is called at the beginning of inserting or updating a record.
* This method is called at the beginning of inserting or updating a record.
* The default implementation will trigger a
[[beforeInsert
]] event when `$insert` is true,
* The default implementation will trigger a
n [[EVENT_BEFORE_INSERT
]] event when `$insert` is true,
* or a
[[beforeUpdate
]] event if `$insert` is false.
* or a
n [[EVENT_BEFORE_UPDATE
]] event if `$insert` is false.
* When overriding this method, make sure you call the parent implementation like the following:
* When overriding this method, make sure you call the parent implementation like the following:
*
*
* ~~~
* ~~~
...
@@ -854,8 +856,8 @@ class ActiveRecord extends Model
...
@@ -854,8 +856,8 @@ class ActiveRecord extends Model
/**
/**
* This method is called at the end of inserting or updating a record.
* This method is called at the end of inserting or updating a record.
* The default implementation will trigger an [[
afterInsert
]] event when `$insert` is true,
* The default implementation will trigger an [[
EVENT_AFTER_INSERT
]] event when `$insert` is true,
* or an [[
afterUpdate
]] event if `$insert` is false.
* or an [[
EVENT_AFTER_UPDATE
]] event if `$insert` is false.
* When overriding this method, make sure you call the parent implementation so that
* When overriding this method, make sure you call the parent implementation so that
* the event is triggered.
* the event is triggered.
* @param boolean $insert whether this method called while inserting a record.
* @param boolean $insert whether this method called while inserting a record.
...
@@ -868,7 +870,7 @@ class ActiveRecord extends Model
...
@@ -868,7 +870,7 @@ class ActiveRecord extends Model
/**
/**
* This method is invoked before deleting a record.
* This method is invoked before deleting a record.
* The default implementation raises the [[
beforeDelete
]] event.
* The default implementation raises the [[
EVENT_BEFORE_DELETE
]] event.
* When overriding this method, make sure you call the parent implementation like the following:
* When overriding this method, make sure you call the parent implementation like the following:
*
*
* ~~~
* ~~~
...
@@ -894,7 +896,7 @@ class ActiveRecord extends Model
...
@@ -894,7 +896,7 @@ class ActiveRecord extends Model
/**
/**
* This method is invoked after deleting a record.
* This method is invoked after deleting a record.
* The default implementation raises the [[
afterDelete
]] event.
* The default implementation raises the [[
EVENT_AFTER_DELETE
]] event.
* You may override this method to do postprocessing after the record is deleted.
* You may override this method to do postprocessing after the record is deleted.
* Make sure you call the parent implementation so that the event is raised properly.
* Make sure you call the parent implementation so that the event is raised properly.
*/
*/
...
...
framework/db/Connection.php
View file @
76b153a3
...
@@ -375,7 +375,7 @@ class Connection extends Component
...
@@ -375,7 +375,7 @@ class Connection extends Component
* This method is invoked right after the DB connection is established.
* This method is invoked right after the DB connection is established.
* The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`
* The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`
* if [[emulatePrepare]] is true, and sets the database [[charset]] if it is not empty.
* if [[emulatePrepare]] is true, and sets the database [[charset]] if it is not empty.
* It then triggers an [[
afterOpen
]] event.
* It then triggers an [[
EVENT_AFTER_OPEN
]] event.
*/
*/
protected
function
initConnection
()
protected
function
initConnection
()
{
{
...
...
framework/logging/Logger.php
View file @
76b153a3
...
@@ -133,7 +133,7 @@ class Logger extends \yii\base\Component
...
@@ -133,7 +133,7 @@ class Logger extends \yii\base\Component
/**
/**
* Flushes log messages from memory to targets.
* Flushes log messages from memory to targets.
* This method will trigger a
[[flush]] or [[finalFlush
]] event depending on the $final value.
* This method will trigger a
n [[EVENT_FLUSH]] or [[EVENT_FINAL_FLUSH
]] event depending on the $final value.
* @param boolean $final whether this is a final call during a request.
* @param boolean $final whether this is a final call during a request.
*/
*/
public
function
flush
(
$final
=
false
)
public
function
flush
(
$final
=
false
)
...
...
framework/logging/Router.php
View file @
76b153a3
...
@@ -69,8 +69,8 @@ class Router extends Component
...
@@ -69,8 +69,8 @@ class Router extends Component
/**
/**
* Initializes this application component.
* Initializes this application component.
* This method is invoked when the Router component is created by the application.
* This method is invoked when the Router component is created by the application.
* The method attaches the [[processLogs]] method to both the [[Logger::
flush
]] event
* The method attaches the [[processLogs]] method to both the [[Logger::
EVENT_FLUSH
]] event
* and the [[
\yii\base\Application::afterRequest
]] event.
* and the [[
Logger::EVENT_FINAL_FLUSH
]] event.
*/
*/
public
function
init
()
public
function
init
()
{
{
...
@@ -88,8 +88,8 @@ class Router extends Component
...
@@ -88,8 +88,8 @@ class Router extends Component
/**
/**
* Retrieves and processes log messages from the system logger.
* Retrieves and processes log messages from the system logger.
* This method mainly serves the event handler to
[[Logger::flush]]
* This method mainly serves the event handler to
the [[Logger::EVENT_FLUSH]] event
* and
[[Application::endRequest]] events
.
* and
the [[Logger::EVENT_FINAL_FLUSH]] event
.
* It will retrieve the available log messages from the [[Yii::getLogger()|system logger]]
* It will retrieve the available log messages from the [[Yii::getLogger()|system logger]]
* and invoke the registered [[targets|log targets]] to do the actual processing.
* and invoke the registered [[targets|log targets]] to do the actual processing.
* @param \yii\base\Event $event event parameter
* @param \yii\base\Event $event event parameter
...
...
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