mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-16 15:21:13 +08:00
update-structure-extensions.md
This commit is contained in:
@ -1,36 +1,35 @@
|
||||
Extensions
|
||||
<EFBFBD><EFBFBD>չ
|
||||
==========
|
||||
|
||||
Extensions are redistributable software packages specifically designed to be used in Yii applications and provide
|
||||
ready-to-use features. For example, the [yiisoft/yii2-debug](tool-debugger.md) extension adds a handy debug toolbar
|
||||
at the bottom of every page in your application to help you more easily grasp how the pages are generated. You can
|
||||
use extensions to accelerate your development process. You can also package your code as extensions to share with
|
||||
other people your great work.
|
||||
<EFBFBD><EFBFBD>չ<EFBFBD>ǿ<EFBFBD><EFBFBD>ٷ<EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ר<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>YiiӦ<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ص㡣<EFBFBD><EFBFBD><EFBFBD>磬
|
||||
<EFBFBD><EFBFBD>Ӧ<EFBFBD>õ<EFBFBD>ÿ<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD>Ϊ [yiisoft/yii2-debug](tool-debugger.md) <EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԵĹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵġ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>.
|
||||
|
||||
> Info: We use the term "extension" to refer to Yii-specific software packages. For general purpose software packages
|
||||
that can be used without Yii, we will refer to them using the term "package" or "library".
|
||||
> <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>Ϣ: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "extension" <20><><EFBFBD><EFBFBD>ָ Yii <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD> Yii <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><EFBFBD>á<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⡱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ǡ<EFBFBD>
|
||||
|
||||
|
||||
## Using Extensions <a name="using-extensions"></a>
|
||||
## <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ <a name="using-extensions"></a>
|
||||
|
||||
To use an extension, you need to install it first. Most extensions are distributed as [Composer](https://getcomposer.org/)
|
||||
packages which can be installed by taking the following two simple steps:
|
||||
Ϊ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [Composer](https://getcomposer.org/)
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Composer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<F2B5A5B5><C4B2>谲װ<E8B0B2><D7B0>
|
||||
|
||||
1. modify the `composer.json` file of your application and specify which extensions (Composer packages) you want to install.
|
||||
2. run `composer install` to install the specified extensions.
|
||||
1. <EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> `composer.json` <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ļ<EFBFBD> (Composer packages)<29><>
|
||||
2. <EFBFBD><EFBFBD><EFBFBD><EFBFBD> `composer install` <EFBFBD><EFBFBD><EFBFBD><EFBFBD>װָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
Note that you may need to install [Composer](https://getcomposer.org/) if you do not have it.
|
||||
<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>еĻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>װ [Composer](https://getcomposer.org/)<EFBFBD><EFBFBD>
|
||||
|
||||
By default, Composer installs packages registered on [Packagist](https://packagist.org/) - the biggest repository
|
||||
for open source Composer packages. You can look for extensions on Packagist. You may also
|
||||
Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>Composer <20><>װ<EFBFBD><D7B0>ע<EFBFBD><D7A2><EFBFBD><EFBFBD> [Packagist](https://packagist.org/) - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>Դ
|
||||
Composer <20><><EFBFBD>⡣<EFBFBD><E2A1A3><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ſ<EFBFBD>һ<EFBFBD><D2BB> Packagist <EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>You may also
|
||||
[create your own repository](https://getcomposer.org/doc/05-repositories.md#repository) and configure Composer
|
||||
to use it. This is useful if you are developing closed open extensions and want to share within your projects.
|
||||
|
||||
Extensions installed by Composer are stored in the `BasePath/vendor` directory, where `BasePath` refers to the
|
||||
application's [base path](structure-applications.md#basePath). Because Composer is a dependency manager, when
|
||||
it installs a package, it will also install all its dependent packages.
|
||||
application's [base path](structure-applications.md#basePath). Because Composer is a dependency manager, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD>װһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҲҪ<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
For example, to install the `yiisoft/yii2-imagine` extension, modify your `composer.json` like the following:
|
||||
<EFBFBD><EFBFBD><EFBFBD>磬Ϊ<EFBFBD>˰<EFBFBD>װ `yiisoft/yii2-imagine` <20><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ʽ<EFBFBD><EFBFBD> `composer.json` <20>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -44,15 +43,15 @@ For example, to install the `yiisoft/yii2-imagine` extension, modify your `compo
|
||||
}
|
||||
```
|
||||
|
||||
After the installation, you should see the directory `yiisoft/yii2-imagine` under `BasePath/vendor`. You should
|
||||
also see another directory `imagine/imagine` which contains the installed dependent package.
|
||||
<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>鿴 `BasePath/vendor` <20>µ<EFBFBD> `yiisoft/yii2-imagine` Ŀ¼<C4BF><C2BC>ͬʱ<CDAC><CAB1>Ҫ<EFBFBD>鿴
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> `imagine/imagine` Ŀ¼<C4BF><C2BC>
|
||||
|
||||
> Info: The `yiisoft/yii2-imagine` is a core extension developed and maintained by the Yii developer team. All
|
||||
> <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>`yiisoft/yii2-imagine` <EFBFBD><EFBFBD><EFBFBD><EFBFBD> Yii <20>Ŷӿ<C5B6><D3BF><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9>All
|
||||
core extensions are hosted on [Packagist](https://packagist.org/) and named like `yiisoft/yii2-xyz`, where `xyz`
|
||||
varies for different extensions.
|
||||
|
||||
Now you can use the installed extensions like they are part of your application. The following example shows
|
||||
how you can use the `yii\imagine\Image` class provided by the `yiisoft/yii2-imagine` extension:
|
||||
Now you can use the installed extensions like they are part of your application. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չʾ<EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> `yiisoft/yii2-imagine` <20><>չ<EFBFBD>ṩ<EFBFBD><E1B9A9> `yii\imagine\Image` <20>ࣺ
|
||||
|
||||
```php
|
||||
use Yii;
|
||||
@ -63,20 +62,20 @@ Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)
|
||||
->save(Yii::getAlias('@runtime/thumb-test-image.jpg'), ['quality' => 50]);
|
||||
```
|
||||
|
||||
> Info: Extension classes are autoloaded by the [Yii class autoloader](concept-autoloading.md).
|
||||
> <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> [Yii class autoloader](concept-autoloading.md) <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ء<EFBFBD>
|
||||
|
||||
|
||||
### Installing Extensions Manually <a name="installing-extensions-manually"></a>
|
||||
### <EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>չ <a name="installing-extensions-manually"></a>
|
||||
|
||||
In some rare occasions, you may want to install some or all extensions manually, rather than relying on Composer.
|
||||
To do so, you should
|
||||
ijЩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Composer<EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
1. download the extension archive files and unpack them in the `vendor` directory.
|
||||
2. install the class autoloaders provided by the extensions, if any.
|
||||
3. download and install all dependent extensions as instructed.
|
||||
1. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>浵<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD> `vendor` Ŀ¼<EFBFBD><EFBFBD>
|
||||
2. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ṩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
3. <EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
If an extension does not have a class autoloader but follows the [PSR-4 standard](http://www.php-fig.org/psr/psr-4/),
|
||||
you may use the class autoloader provided by Yii to autoload the extension classes. All you need to do is just to
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չû<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>൫<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ [PSR-4 standard](http://www.php-fig.org/psr/psr-4/),
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>yii<EFBFBD>ṩ<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ࡣAll you need to do is just to
|
||||
declare a [root alias](concept-aliases.md#defining-aliases) for the extension root directory. For example,
|
||||
assuming you have installed an extension in the directory `vendor/mycompany/myext`, and the extension classes
|
||||
are under the `myext` namespace, then you can include the following code in your application configuration:
|
||||
@ -90,15 +89,15 @@ are under the `myext` namespace, then you can include the following code in your
|
||||
```
|
||||
|
||||
|
||||
## Creating Extensions <a name="creating-extensions"></a>
|
||||
## <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ <a name="creating-extensions"></a>
|
||||
|
||||
You may consider creating an extension when you feel the need to share with other people your great code.
|
||||
An extension can contain any code you like, such as a helper class, a widget, a module, etc.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD>룬<EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD>Ǵ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ܹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κδ<EFBFBD><EFBFBD>룬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>࣬a widget, a module, etc.
|
||||
|
||||
It is recommended that you create an extension in terms of a [Composer package](https://getcomposer.org/) so that
|
||||
it can be more easily installed and used by other users, liked described in the last subsection.
|
||||
|
||||
Below are the basic steps you may follow to create an extension as a Composer package.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±߲<EFBFBD><EFBFBD><EFBFBD>Ϊ Composer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>չ<EFBFBD><D5B9>
|
||||
|
||||
1. Create a project for your extension and host it on a VCS repository, such as [github.com](https://github.com).
|
||||
The development and maintenance work about the extension should be done on this repository.
|
||||
@ -110,9 +109,9 @@ Below are the basic steps you may follow to create an extension as a Composer pa
|
||||
|
||||
### `composer.json` <a name="composer-json"></a>
|
||||
|
||||
Each Composer package must have a `composer.json` file in its root directory. The file contains the metadata about
|
||||
the package. You may find complete specification about this file in the [Composer Manual](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup).
|
||||
The following example shows the `composer.json` file for the `yiisoft/yii2-imagine` extension:
|
||||
ÿһ<EFBFBD><EFBFBD> Composer package <EFBFBD>ĸ<EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> `composer.json` <20>ļ<EFBFBD><C4BC><EFBFBD>The file contains the metadata about
|
||||
the package. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [Composer Manual](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup) <20>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>йظ<D0B9><D8B8>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>
|
||||
<EFBFBD>±<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չʾ<EFBFBD><EFBFBD> `composer.json` <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD> `yiisoft/yii2-imagine` <EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -157,8 +156,8 @@ The following example shows the `composer.json` file for the `yiisoft/yii2-imagi
|
||||
|
||||
#### Package Name <a name="package-name"></a>
|
||||
|
||||
Each Composer package should have a package name which uniquely identifies the package among all others.
|
||||
The format of package names is `vendorName/projectName`. For example, in the package name `yiisoft/yii2-imagine`,
|
||||
ÿһ<EFBFBD><EFBFBD> Composer <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
The format of package names is `vendorName/projectName`. <EFBFBD><EFBFBD><EFBFBD>磬in the package name `yiisoft/yii2-imagine`,
|
||||
the vendor name and the project name are `yiisoft` and `yii2-imagine`, respectively.
|
||||
|
||||
Do NOT use `yiisoft` as vendor name as it is reserved for use by the Yii core code.
|
||||
@ -172,15 +171,15 @@ We recommend you prefix `yii2-` to the project name for packages representing Yi
|
||||
It is important that you specify the package type of your extension as `yii2-extension` so that the package can
|
||||
be recognized as a Yii extension when being installed.
|
||||
|
||||
When a user runs `composer install` to install an extension, the file `vendor/yiisoft/extensions.php`
|
||||
will be automatically updated to include the information about the new extension. From this file, Yii applications
|
||||
can know which extensions are installed (the information can be accessed via [[yii\base\Application::extensions]].
|
||||
<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> `composer install` <EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>`vendor/yiisoft/extensions.php`<EFBFBD>ļ<EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֪<EFBFBD><EFBFBD> Yii Ӧ<><D3A6>
|
||||
<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD>չ (the information can be accessed via [[yii\base\Application::extensions]].
|
||||
|
||||
|
||||
#### Dependencies <a name="dependencies"></a>
|
||||
|
||||
Your extension depends on Yii (of course). So you should list it (`yiisoft/yii2`) in the `require` entry in `composer.json`.
|
||||
If your extension also depends on other extensions or third-party libraries, you should list them as well.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Yii (of course)<EFBFBD><EFBFBD>So you should list it (`yiisoft/yii2`) in the `require` entry in `composer.json`.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD>ҲҪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Make sure you also list appropriate version constraints (e.g. `1.*`, `@stable`) for each dependent package. Use stable
|
||||
dependencies when your extension is released in a stable version.
|
||||
|
||||
@ -198,19 +197,19 @@ simply list the dependency in `composer.json` like the following:
|
||||
}
|
||||
```
|
||||
|
||||
The above code states that the extension depends on the `jquery` Bower package. In general, you can use
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> `jquery` Bower package<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>you can use
|
||||
`bower-asset/PackageName` to refer to a Bower package in `composer.json`, and use `npm-asset/PackageName`
|
||||
to refer to a NPM package. When Composer installs a Bower or NPM package, by default the package content will be
|
||||
installed under the `@vendor/bower/PackageName` and `@vendor/npm/Packages` directories, respectively.
|
||||
These two directories can also be referred to using the shorter aliases `@bower/PackageName` and `@npm/PackageName`.
|
||||
|
||||
For more details about asset management, please refer to the [Assets](structure-assets.md#bower-npm-assets) section.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD> [Assets](structure-assets.md#bower-npm-assets) <EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>
|
||||
|
||||
|
||||
#### Class Autoloading <a name="class-autoloading"></a>
|
||||
|
||||
In order for your classes to be autoloaded by the Yii class autoloader or the Composer class autoloader,
|
||||
you should specify the `autoload` entry in the `composer.json` file, like shown below:
|
||||
you should specify the `autoload` entry in the `composer.json` file, <EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -226,9 +225,9 @@ you should specify the `autoload` entry in the `composer.json` file, like shown
|
||||
|
||||
You may list one or multiple root namespaces and their corresponding file paths.
|
||||
|
||||
When the extension is installed in an application, Yii will create for each listed root namespace
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>װһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չʱ<EFBFBD><EFBFBD>Yii will create for each listed root namespace
|
||||
an [alias](concept-aliases.md#extension-aliases) that refers to the directory corresponding to the namespace.
|
||||
For example, the above `autoload` declaration will correspond to an alias named `@yii/imagine`.
|
||||
<EFBFBD><EFBFBD><EFBFBD>磬the above `autoload` declaration will correspond to an alias named `@yii/imagine`.
|
||||
|
||||
|
||||
### Recommended Practices <a name="recommended-practices"></a>
|
||||
@ -237,9 +236,9 @@ Because extensions are meant to be used by other people, you often need to take
|
||||
we introduce some common and recommended practices in creating high quality extensions.
|
||||
|
||||
|
||||
#### Namespaces <a name="namespaces"></a>
|
||||
#### <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD> <a name="namespaces"></a>
|
||||
|
||||
To avoid name collisions and make the classes in your extension autoloadable, you should use namespaces and
|
||||
Ϊ<EFBFBD>˱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD>ͻ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>you should use namespaces and
|
||||
name the classes in your extension by following the [PSR-4 standard](http://www.php-fig.org/psr/psr-4/) or
|
||||
[PSR-0 standard](http://www.php-fig.org/psr/psr-0/).
|
||||
|
||||
@ -247,18 +246,18 @@ You class namespaces should start with `vendorName\extensionName`, where `extens
|
||||
in the package name except that it should not contain the `yii2-` prefix. For example, for the `yiisoft/yii2-imagine`
|
||||
extension, we use `yii\imagine` as the namespace its classes.
|
||||
|
||||
Do not use `yii`, `yii2` or `yiisoft` as vendor name. These names are reserved for use by the Yii core code.
|
||||
<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD> `yii`, `yii2` or `yiisoft` <EFBFBD><EFBFBD>Ϊ vendor <EFBFBD><EFBFBD><EFBFBD>ơ<EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Yii <20><><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ʹ<EFBFBD>õġ<C3B5>
|
||||
|
||||
|
||||
#### Bootstrapping Classes <a name="bootstrapping-classes"></a>
|
||||
|
||||
Sometimes, you may want your extension to execute some code during the [bootstrapping process](runtime-bootstrapping.md)
|
||||
stage of an application. For example, your extension may want to respond to the application's `beginRequest` event
|
||||
ijЩʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>you may want your extension to execute some code during the [bootstrapping process](runtime-bootstrapping.md)
|
||||
stage of an application. <EFBFBD><EFBFBD><EFBFBD>磬your extension may want to respond to the application's `beginRequest` event
|
||||
to adjust some environment settings. While you can instruct users of the extension to explicitly attach your event
|
||||
handler in the extension to the `beginRequest` event, a better way is to do this automatically.
|
||||
handler in the extension to the `beginRequest` event, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
To achieve this goal, you can create a so-called *bootstrapping class* by implementing [[yii\base\BootstrapInterface]].
|
||||
For example,
|
||||
Ϊ<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һĿ<EFBFBD>꣬you can create a so-called *bootstrapping class* by implementing [[yii\base\BootstrapInterface]].
|
||||
<EFBFBD><EFBFBD><EFBFBD>磬
|
||||
|
||||
```php
|
||||
namespace myname\mywidget;
|
||||
@ -289,29 +288,29 @@ You then list this class in the `composer.json` file of your extension like foll
|
||||
}
|
||||
```
|
||||
|
||||
When the extension is installed in an application, Yii will automatically instantiate the bootstrapping class
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>װһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չʱ<EFBFBD><EFBFBD>Yii will automatically instantiate the bootstrapping class
|
||||
and call its [[yii\base\BootstrapInterface::bootstrap()|bootstrap()]] method during the bootstrapping process for
|
||||
every request.
|
||||
|
||||
|
||||
#### Working with Databases <a name="working-with-databases"></a>
|
||||
|
||||
Your extension may need to access databases. Do not assume that the applications that use your extension will always
|
||||
use `Yii::$db` as the DB connection. Instead, you should declare a `db` property for the classes that require DB access.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ⡣Do not assume that the applications that use your extension will always
|
||||
use `Yii::$db` as the DB connection. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>you should declare a `db` property for the classes that require DB access.
|
||||
The property will allow users of your extension to customize which DB connection they would like your extension to use.
|
||||
As an example, you may refer to the [[yii\caching\DbCache]] class and see how it declares and uses the `db` property.
|
||||
<EFBFBD>ٸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>you may refer to the [[yii\caching\DbCache]] class and see how it declares and uses the `db` property.
|
||||
|
||||
If your extension needs to create specific DB tables or make changes to DB schema, you should
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD> DB tables <20><><EFBFBD><EFBFBD> Ҫ<>ı<EFBFBD> DB schema<6D><61><EFBFBD><EFBFBD>Ҫ
|
||||
|
||||
- provide [migrations](db-migrations.md) to manipulate DB schema, rather than using plain SQL files;
|
||||
- try to make the migrations applicable to different DBMS;
|
||||
- avoid using [Active Record](db-active-record.md) in the migrations.
|
||||
- <EFBFBD>ṩ [migrations](db-migrations.md) <EFBFBD><EFBFBD><EFBFBD>ٿ<EFBFBD> DB schema<6D><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> SQL <20>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǩ<EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD> DBMS<EFBFBD><EFBFBD>
|
||||
- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> migrations <20>е<EFBFBD> [Active Record](db-active-record.md)<EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
#### Using Assets <a name="using-assets"></a>
|
||||
|
||||
If your extension is a widget or a module, chances are that it may require some [assets](structure-assets.md) to work.
|
||||
For example, a module may display some pages which contain images, JavaScript, and CSS. Because the files of an
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD> a widget <EFBFBD><EFBFBD><EFBFBD><EFBFBD> a module<EFBFBD><EFBFBD>chances are that it may require some [assets](structure-assets.md) to work.
|
||||
<EFBFBD><EFBFBD><EFBFBD>磬<EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><EFBFBD><EFBFBD>ʾһЩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> images, JavaScript, and CSS <EFBFBD><EFBFBD>ҳ<EFBFBD>档Because the files of an
|
||||
extension are all under the same directory which is not Web accessible when installed in an application, you have
|
||||
two choices to make the asset files directly accessible via Web:
|
||||
|
||||
@ -325,7 +324,7 @@ Please refer to the [Assets](structure-assets.md) section for more details about
|
||||
|
||||
#### Internationalization and Localization <a name="i18n-l10n"></a>
|
||||
|
||||
Your extension may be used by applications supporting different languages! Therefore, if your extension displays
|
||||
Your extension may be used by applications supporting different languages! <EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>if your extension displays
|
||||
content to end users, you should try to [internationalize and localize](tutorial-i18n.md) it. In particular,
|
||||
|
||||
- If the extension displays messages intended for end users, the messages should be wrapped into `Yii::t()`
|
||||
@ -334,66 +333,66 @@ content to end users, you should try to [internationalize and localize](tutorial
|
||||
- If the extension displays numbers, dates, etc., they should be formatted using [[yii\i18n\Formatter]] with
|
||||
appropriate formatting rules.
|
||||
|
||||
For more details, please refer to the [Internationalization](tutorial-i18n.md) section.
|
||||
<EFBFBD>˽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD> [Internationalization](tutorial-i18n.md) <EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
||||
|
||||
|
||||
#### Testing <a name="testing"></a>
|
||||
#### <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <a name="testing"></a>
|
||||
|
||||
You want your extension to run flawlessly without bringing problems to other people. To reach this goal, you should
|
||||
test your extension before releasing it to public.
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չû<EFBFBD>к<EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD>ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>Ϊ<EFBFBD>˴ﵽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
||||
<EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չǰ<EFBFBD>Ȳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
It is recommended that you create various test cases to cover your extension code rather than relying on manual tests.
|
||||
Each time before you release a new version of your extension, you may simply run these test cases to make sure
|
||||
everything is in good shape. Yii provides testing support, which can help you to more easily write unit tests,
|
||||
acceptance tests and functionality tests. For more details, please refer to the [Testing](test-overview.md) section.
|
||||
ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㷢<EFBFBD><EFBFBD><EFBFBD>°汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ֮ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
everything is in good shape. Yii <EFBFBD>ṩ<EFBFBD>˲<EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD>ղ<EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD>ԡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD> [Testing](test-overview.md) <EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>
|
||||
|
||||
|
||||
#### Versioning <a name="versioning"></a>
|
||||
|
||||
You should give each release of your extension a version number (e.g. `1.0.1`). We recommend you follow the
|
||||
<EFBFBD><EFBFBD>Ӧ<EFBFBD>ø<EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><EFBFBD> (e.g. `1.0.1`)<EFBFBD><EFBFBD>We recommend you follow the
|
||||
[semantic versioning](http://semver.org) practice when determining what version numbers should be used.
|
||||
|
||||
|
||||
#### Releasing <a name="releasing"></a>
|
||||
|
||||
To let other people know your extension, you need to release it to public.
|
||||
Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֪<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>
|
||||
|
||||
If it is the first time you release an extension, you should register it on a Composer repository, such as
|
||||
[Packagist](https://packagist.org/). After that, all you need to do is simply creating a release tag (e.g. `v1.0.1`)
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>η<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Composer <20><><EFBFBD><EFBFBD>ע<EFBFBD>ᣬ<EFBFBD><E1A3AC><EFBFBD><EFBFBD>
|
||||
[Packagist](https://packagist.org/)<EFBFBD><EFBFBD> After that, all you need to do is simply creating a release tag (e.g. `v1.0.1`)
|
||||
on the VCS repository of your extension and notify the Composer repository about the new release. People will
|
||||
then be able to find the new release, and install or update the extension through the Composer repository.
|
||||
|
||||
In the releases of your extension, besides code files you should also consider including the followings to
|
||||
help other people learn about and use your extension:
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>İ汾<EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>㻹<EFBFBD><EFBFBD>Ҫע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>
|
||||
|
||||
* A readme file in the package root directory: it describes what your extension does and how to install and use it.
|
||||
* <EFBFBD>ڰ<EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD> readme <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ΰ<EFBFBD>װ<EFBFBD><D7B0>ʹ<EFBFBD><CAB9>.
|
||||
We recommend you write it in [Markdown](http://daringfireball.net/projects/markdown/) format and name the file
|
||||
as `readme.md`.
|
||||
* A changelog file in the package root directory: it lists what changes are made in each release. The file
|
||||
may be written in Markdown format and named as `changelog.md`.
|
||||
* An upgrade file in the package root directory: it gives the instructions on how to upgrade from older releases
|
||||
of the extension. The file may be written in Markdown format and named as `upgrade.md`.
|
||||
* Tutorials, demos, screenshots, etc.: these are needed if your extension provides many features that cannot be
|
||||
* <EFBFBD>ڰ<EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD>и<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı仯<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>д<EFBFBD><EFBFBD> Markdown <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ `changelog.md`<EFBFBD><EFBFBD>
|
||||
* <EFBFBD>ڰ<EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δӾɰ汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>д<EFBFBD><EFBFBD> Markdown <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ `upgrade.md`<EFBFBD><EFBFBD>
|
||||
* <EFBFBD>̳̣<EFBFBD>demos, screenshots, etc.: these are needed if your extension provides many features that cannot be
|
||||
fully covered in the readme file.
|
||||
* API documentation: your code should be well documented to allow other people more easily read and understand it.
|
||||
You may refer to the [Object class file](https://github.com/yiisoft/yii2/blob/master/framework/base/Object.php)
|
||||
to learn how to document your code.
|
||||
* API documentation:<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>úúõؼ<EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բο<EFBFBD> [Object class file](https://github.com/yiisoft/yii2/blob/master/framework/base/Object.php)
|
||||
<EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD>롣
|
||||
|
||||
> Info: Your code comments can be written in Markdown format. The `yiisoft/yii2-apidoc` extension provides a tool
|
||||
for you to generate pretty API documentation based on your code comments.
|
||||
> <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ע<EFBFBD>Ϳ<EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD> Markdown <20><>ʽ<EFBFBD><CABD>`yiisoft/yii2-apidoc` <20><>չΪ<D5B9><CEAA><EFBFBD>ṩ<EFBFBD><E1B9A9>һ
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> API <20>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ߡ<EFBFBD>
|
||||
|
||||
> Info: While not a requirement, we suggest your extension adhere to certain coding styles. You may refer to
|
||||
the [core framework code style](https://github.com/yiisoft/yii2/wiki/Core-framework-code-style).
|
||||
> <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD>ο<EFBFBD> [core framework code style](https://github.com/yiisoft/yii2/wiki/Core-framework-code-style)<EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
## Core Extensions <a name="core-extensions"></a>
|
||||
|
||||
Yii provides the following core extensions that are developed and maintained by the Yii developer team. They are all
|
||||
registered on [Packagist](https://packagist.org/) and can be easily installed as described in the
|
||||
[Using Extensions](#using-extensions) subsection.
|
||||
Yii <EFBFBD>ṩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>º<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Yii <20><><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD>ά<EFBFBD><CEAC><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>
|
||||
[Packagist](https://packagist.org/) ע<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD>ҿ<EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>
|
||||
[Using Extensions](#using-extensions) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
||||
|
||||
- [yiisoft/yii2-apidoc](https://github.com/yiisoft/yii2-apidoc):
|
||||
provides an extensible and high-performance API documentation generator. It is also used to generate the core
|
||||
<EFBFBD>ṩһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD> API <20>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>It is also used to generate the core
|
||||
framework API documentation.
|
||||
- [yiisoft/yii2-authclient](https://github.com/yiisoft/yii2-authclient):
|
||||
provides a set of commonly used auth clients, such as Facebook OAuth2 client, GitHub OAuth2 client.
|
||||
|
Reference in New Issue
Block a user