mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
proof reading docs, fixed event order in AR
This commit is contained in:
@ -7,7 +7,7 @@ is triggered (i.e. comment will be added), our custom code will be executed.
|
||||
|
||||
An event is identified by a name that should be unique within the class it is defined at. Event names are *case-sensitive*.
|
||||
|
||||
One or multiple PHP callbacks, called *event handlers*, could be attached to event. You can call [[trigger()]] to
|
||||
One or multiple PHP callbacks, called *event handlers*, could be attached to an event. You can call [[trigger()]] to
|
||||
raise an event. When an event is raised, the event handlers will be invoked automatically in the order they were
|
||||
attached.
|
||||
|
||||
@ -24,7 +24,7 @@ Valid event handlers include:
|
||||
|
||||
- anonymous function: `function($event) { ... }`
|
||||
- object method: `array($object, 'handleAdd')`
|
||||
- static method: `array('Page', 'handleAdd')`
|
||||
- static class method: `array('Page', 'handleAdd')`
|
||||
- global function: `'handleAdd'`
|
||||
|
||||
The signature of an event handler should be like the following:
|
||||
|
@ -31,6 +31,3 @@ If a property has only a getter method and has no setter method, it is considere
|
||||
to modify the property value will cause an exception.
|
||||
|
||||
One can call [[hasProperty]], [[canGetProperty]] and/or [[canSetProperty]] to check the existence of a property.
|
||||
|
||||
Besides the property feature, the Object class defines a static method [[create]] which provides a convenient
|
||||
alternative way of creating a new object instance.
|
||||
|
@ -1,5 +1,5 @@
|
||||
ActiveRecord implements the [Active Record design pattern](http://en.wikipedia.org/wiki/Active_record).
|
||||
The idea is that ActiveRecord object is associated with a row in a database table
|
||||
The idea is that an ActiveRecord object is associated with a row in a database table
|
||||
so object properties are mapped to colums of the corresponding database row.
|
||||
For example, a `Customer` object is associated with a row in the `tbl_customer`
|
||||
table. Instead of writing raw SQL statements to access the data in the table,
|
||||
@ -62,7 +62,7 @@ There are two ActiveRecord methods for getting data:
|
||||
- [[find()]]
|
||||
- [[findBySql()]]
|
||||
|
||||
They all return an [[ActiveQuery]] instance. Coupled with the various customization and query methods
|
||||
They both return an [[ActiveQuery]] instance. Coupled with the various customization and query methods
|
||||
provided by [[ActiveQuery]], ActiveRecord supports very flexible and powerful data retrieval approaches.
|
||||
|
||||
The followings are some examples,
|
||||
@ -158,7 +158,7 @@ $customer = Customer::find($id);
|
||||
$customer->delete();
|
||||
|
||||
// to increment the age of all customers by 1
|
||||
Customer::updateAllCounters(array('age' => +1));
|
||||
Customer::updateAllCounters(array('age' => 1));
|
||||
~~~
|
||||
|
||||
|
||||
@ -386,10 +386,10 @@ When getting an ActiveRecord instance through the [[find()]] method, we will hav
|
||||
When calling [[save()]] to insert or update an ActiveRecord, we will have the following life cycles:
|
||||
|
||||
1. [[beforeValidate()]]: will trigger an [[EVENT_BEFORE_VALIDATE]] event
|
||||
2. [[beforeSave()]]: will trigger an [[EVENT_BEFORE_INSERT]] or [[EVENT_BEFORE_UPDATE]] event
|
||||
3. perform the actual data insertion or updating
|
||||
4. [[afterSave()]]: will trigger an [[EVENT_AFTER_INSERT]] or [[EVENT_AFTER_UPDATE]] event
|
||||
5. [[afterValidate()]]: will trigger an [[EVENT_AFTER_VALIDATE]] event
|
||||
2. [[afterValidate()]]: will trigger an [[EVENT_AFTER_VALIDATE]] event
|
||||
3. [[beforeSave()]]: will trigger an [[EVENT_BEFORE_INSERT]] or [[EVENT_BEFORE_UPDATE]] event
|
||||
4. perform the actual data insertion or updating
|
||||
5. [[afterSave()]]: will trigger an [[EVENT_AFTER_INSERT]] or [[EVENT_AFTER_UPDATE]] event
|
||||
|
||||
Finally when calling [[delete()]] to delete an ActiveRecord, we will have the following life cycles:
|
||||
|
||||
|
Reference in New Issue
Block a user