Home  >  Article  >  PHP Framework  >  What are the extensions of yii framework

What are the extensions of yii framework

(*-*)浩
(*-*)浩Original
2020-01-02 15:06:562101browse

What are the extensions of yii framework

Extensions are specially designed software packages that can be used at any time in Yii applications and can be redistributed.               (Recommended learning: yii tutorial)

For example, the yiisoft/yii2-debug extension adds a convenient tool for debugging at the bottom of each page of your application bar to help you simply scrape the page generated. You can use extensions to speed up your development process.

Information: We use the term "extension" specifically to refer to Yii packages. The terms "package" and "library" are used to refer to general software packages that are not specific to Yii.

Using extensions

To use an extension, you need to install it first. Most extensions are released as Composer packages. Such extensions can be installed in the following two steps:

Modify your application's composer.json file to indicate which extension you want to install (Composer software package).

Run composer install to install the specified extension.

Note that if you haven’t installed Composer yet, you need to install it first.

By default, Composer installs packages registered with Packagist - the largest open source Composer code base. You can find extensions in Packageist. You can also create your own repository and configure Composer to use it.

This is useful if you are developing a private extension and want to share it only among your other projects.

Extensions installed through Composer will be stored in the BasePath/vendor directory, where BasePath refers to the base path of your application. Because Composer is also a dependency manager, when it installs a package, it will also install all the packages that the package depends on.

For example, if you want to install the yiisoft/yii2-imagine extension, you can modify your composer.json file as follows:

{
    // ...
    "require": {
        // ... other dependencies
        "yiisoft/yii2-imagine": "~2.0.0"
    }
}

After the installation is complete, you should be able to install it in BasePath You can see the yiisoft/yii2-imagine directory in the /vendor directory. You should also see another imagine/imagine directory with dependent packages installed.

Information: yiisoft/yii2-imagine is a core extension maintained by the Yii development team. All core extensions are centrally managed by Packagist and named yiisoft/yii2-xyz, where xyz, Different extensions have different names.

Now you can use the installed extension, as if it were part of the application. The following example shows how to use the yii\imagine\Image class provided by yiisoft/yii2-imagine extension:

use Yii;
use yii\imagine\Image;
// generate a thumbnail image
Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)
    ->save(Yii::getAlias('@runtime/thumb-test-image.jpg'), ['quality' => 50]);

Information: The extension class is automatically loaded by Yii class autoloader.

The above is the detailed content of What are the extensions of yii framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn