Browse Source
* master: (30 commits) replaced inheritdoc tags. doc cleanup. Moved key serialization from data provider to data viewers. Fixes #1356: Alias for authFile in rbac/PhpManager not resolved Fixes #1296: stricter check of dashes in route. Fixes #1362: added itemOptions to Html::radioList and checkboxList. Fixes #1362: doc fix. really small doc typo fix Fixes #1332: generate subdirectories when needed during message extraction process. typo fix. Fixes #1335: support view extension fallback More TDB for the guide Added reference to Composer section of the guide from 1.1.x differences page Better docs structure and minor fixes More docs on performance Structure for console application docs Docs on using behaviors doc fix. Refactored MessageInterface::send(). refactored EmailTarget with the new mailer interfaces. ...tags/2.0.0-beta
Carsten Brandt
11 years ago
76 changed files with 501 additions and 286 deletions
@ -1,4 +1,41 @@ |
|||||||
Behaviors |
Behaviors |
||||||
========= |
========= |
||||||
|
|
||||||
TDB |
A behavior (also knows as mixin) can be used to enhance the functionality of an existing component without modifying its |
||||||
|
code. In particular, it can "inject" its own methods and properties into the component and make them directly accessible |
||||||
|
via the component. It can also respond to the events triggered in the component and thus intercept the normal |
||||||
|
code execution. Unlike PHP traits, behaviors could be attached to classes at runtime. |
||||||
|
|
||||||
|
Using behaviors |
||||||
|
--------------- |
||||||
|
|
||||||
|
Behavior can be attached to any class that extends from `Component`. In order to do so you need to implement `behaviors` |
||||||
|
method. Yii provides `AutoTimestamp` behavior that handles updating timestamp fields on saving active record model. |
||||||
|
|
||||||
|
```php |
||||||
|
class User extends ActiveRecord |
||||||
|
{ |
||||||
|
// ... |
||||||
|
|
||||||
|
public function behaviors() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'timestamp' => [ |
||||||
|
'class' => 'yii\behaviors\AutoTimestamp', |
||||||
|
'attributes' => [ |
||||||
|
ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'], |
||||||
|
ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time', |
||||||
|
], |
||||||
|
], |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
In the above `class` value is a string containing fully qualified behavior class name. All the other key-values are |
||||||
|
assigned to corresponding properties of the class. |
||||||
|
|
||||||
|
Creating your own behaviors |
||||||
|
--------------------------- |
||||||
|
|
||||||
|
TBD |
@ -1,4 +1,39 @@ |
|||||||
Building console applications |
Console applications |
||||||
============================= |
==================== |
||||||
|
|
||||||
TDB |
Yii has full featured support of console. Console application structure in Yii is very similar to web application. It |
||||||
|
consists of one or more [[\yii\console\Controller]] (often referred to as commands). Each has one or more actions. |
||||||
|
|
||||||
|
Usage |
||||||
|
----- |
||||||
|
|
||||||
|
User executes controller action using the following syntax: |
||||||
|
|
||||||
|
``` |
||||||
|
yii <route> [--param1=value1 --param2 ...] |
||||||
|
``` |
||||||
|
|
||||||
|
For example, `MigrationController::create` with `MigrationController::$migrationTable` set can be called from command |
||||||
|
line like the following: |
||||||
|
|
||||||
|
``` |
||||||
|
yii migreate/create --migrationTable=my_migration |
||||||
|
``` |
||||||
|
|
||||||
|
Entry script |
||||||
|
------------ |
||||||
|
|
||||||
|
|
||||||
|
Configuration |
||||||
|
------------- |
||||||
|
|
||||||
|
Creating your own console commands |
||||||
|
---------------------------------- |
||||||
|
|
||||||
|
### Controller |
||||||
|
|
||||||
|
### Action |
||||||
|
|
||||||
|
### Parameters |
||||||
|
|
||||||
|
### Return codes |
Loading…
Reference in new issue