forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructuring guide index.md and structure
worked though all the guide files adjusted structure and added some missing does
- Loading branch information
Showing
27 changed files
with
366 additions
and
101 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Creating your own Application structure | ||
======================================= | ||
|
||
TDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Basic concepts of Yii | ||
===================== | ||
|
||
|
||
Component and Object | ||
-------------------- | ||
|
||
Yii 2.0 breaks the `CComponent` class in 1.1 into two classes: `Object` and `Component`. | ||
The `Object` class is a lightweight base class that allows defining class properties | ||
via getters and setters. The `Component` class extends from `Object` and supports | ||
the event feature and the behavior feature. | ||
|
||
If your class does not need the event or behavior feature, you should consider using | ||
`Object` as the base class. This is usually the case for classes that represent basic | ||
data structures. | ||
|
||
|
||
Object Configuration | ||
-------------------- | ||
|
||
The `Object` class introduces a uniform way of configuring objects. Any descendant class | ||
of `Object` should declare its constructor (if needed) in the following way so that | ||
it can be properly configured: | ||
|
||
```php | ||
class MyClass extends \yii\base\Object | ||
{ | ||
public function __construct($param1, $param2, $config = []) | ||
{ | ||
// ... initialization before configuration is applied | ||
|
||
parent::__construct($config); | ||
} | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
// ... initialization after configuration is applied | ||
} | ||
} | ||
``` | ||
|
||
In the above, the last parameter of the constructor must take a configuration array | ||
which contains name-value pairs for initializing the properties at the end of the constructor. | ||
You can override the `init()` method to do initialization work that should be done after | ||
the configuration is applied. | ||
|
||
By following this convention, you will be able to create and configure a new object | ||
using a configuration array like the following: | ||
|
||
```php | ||
$object = Yii::createObject([ | ||
'class' => 'MyClass', | ||
'property1' => 'abc', | ||
'property2' => 'cde', | ||
], $param1, $param2); | ||
``` | ||
|
||
More on configuration in [configuration](configuration.md) | ||
|
||
|
||
Path Alias | ||
---------- | ||
|
||
Yii 2.0 expands the usage of path aliases to both file/directory paths and URLs. An alias | ||
must start with a `@` character so that it can be differentiated from file/directory paths and URLs. | ||
For example, the alias `@yii` refers to the Yii installation directory. Path aliases are | ||
supported in most places in the Yii core code. For example, `FileCache::cachePath` can take | ||
both a path alias and a normal directory path. | ||
|
||
Path alias is also closely related with class namespaces. It is recommended that a path | ||
alias be defined for each root namespace so that you can use Yii the class autoloader without | ||
any further configuration. For example, because `@yii` refers to the Yii installation directory, | ||
a class like `yii\web\Request` can be autoloaded by Yii. If you use a third party library | ||
such as Zend Framework, you may define a path alias `@Zend` which refers to its installation | ||
directory and Yii will be able to autoload any class in this library. | ||
|
||
|
||
Autoloading | ||
----------- | ||
|
||
TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Behaviors | ||
========= | ||
|
||
TDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Building console applications | ||
============================= | ||
|
||
TDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Events | ||
====== | ||
|
||
|
||
There is no longer the need to define an `on`-method in order to define an event in Yii 2.0. | ||
Instead, you can use whatever event names. To attach a handler to an event, you should | ||
use the `on` method now: | ||
|
||
```php | ||
$component->on($eventName, $handler); | ||
// To detach the handler, use: | ||
// $component->off($eventName, $handler); | ||
``` | ||
|
||
|
||
When you attach a handler, you can now associate it with some parameters which can be later | ||
accessed via the event parameter by the handler: | ||
|
||
```php | ||
$component->on($eventName, $handler, $params); | ||
``` | ||
|
||
|
||
Because of this change, you can now use "global" events. Simply trigger and attach handlers to | ||
an event of the application instance: | ||
|
||
```php | ||
Yii::$app->on($eventName, $handler); | ||
.... | ||
// this will trigger the event and cause $handler to be invoked. | ||
Yii::$app->trigger($eventName); | ||
``` | ||
|
||
If you need to handle all instances of a class instead of the object you can attach a handler like the following: | ||
|
||
```php | ||
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, function ($event) { | ||
Yii::trace(get_class($event->sender) . ' is inserted.'); | ||
}); | ||
``` | ||
|
||
The code above defines a handler that will be triggered for every Active Record object's `EVENT_AFTER_INSERT` event. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Extending Yii | ||
============= | ||
|
||
TDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
The Gii code generation tool | ||
============================ | ||
|
||
Yii2 includes a handy tool that allows rapid prototyping by generating commonly used code snippets | ||
as well as complete CRUD controllers. | ||
|
||
Installing and configuring | ||
-------------------------- | ||
|
||
How to use it | ||
------------- | ||
|
||
Add these lines to your config file: | ||
|
||
```php | ||
'modules' => [ | ||
'gii' => ['yii\gii\Module'] | ||
] | ||
``` | ||
|
||
Creating your own templates | ||
--------------------------- | ||
|
||
TDB | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Oops, something went wrong.