PHPackages                             zacksleo/yii2-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. zacksleo/yii2-plugin

ActiveYii2-extension[Framework](/categories/framework)

zacksleo/yii2-plugin
====================

yii2 plugin module

2.1.6(8y ago)95217MITPHPCI failing

Since Jan 18Pushed 8y ago1 watchersCompare

[ Source](https://github.com/zacksleo/yii2-plugin)[ Packagist](https://packagist.org/packages/zacksleo/yii2-plugin)[ RSS](/packages/zacksleo-yii2-plugin/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (0)

Plugin Module
=============

[](#plugin-module)

[![Latest Stable Version](https://camo.githubusercontent.com/054194755133bf92f81741a01ada88c6e34cd62043689c1c288188988d8b4f02/68747470733a2f2f706f7365722e707567782e6f72672f7a61636b736c656f2f796969322d706c7567696e2f76657273696f6e)](https://packagist.org/packages/zacksleo/yii2-plugin)[![Total Downloads](https://camo.githubusercontent.com/7d4decad5184b499a9e5d14f9b3d482626ead9fa31bed5597dae9dcc653de67d/68747470733a2f2f706f7365722e707567782e6f72672f7a61636b736c656f2f796969322d706c7567696e2f646f776e6c6f616473)](https://packagist.org/packages/zacksleo/yii2-plugin)[![License](https://camo.githubusercontent.com/c1277206b8d9b114ebad6c33a64be8ad369ad077e595ea95cfa214a30960e6e5/68747470733a2f2f706f7365722e707567782e6f72672f7a61636b736c656f2f796969322d706c7567696e2f6c6963656e7365)](https://packagist.org/packages/zacksleo/yii2-plugin)

Languages: [English](#) [中文](https://github.com/zacksleo/yii2-plugin/blob/master/README_cn.md)

---

[![cp](https://camo.githubusercontent.com/1fc3f08db91b48556ec2ec2b2703ff5b9928b039f64fec0bc00ddff02005f2a2/687474703a2f2f692e6d696e75732e636f6d2f69626e57354f6850427355626f412e6a7067)](https://camo.githubusercontent.com/1fc3f08db91b48556ec2ec2b2703ff5b9928b039f64fec0bc00ddff02005f2a2/687474703a2f2f692e6d696e75732e636f6d2f69626e57354f6850427355626f412e6a7067)

FEATURES
--------

[](#features)

- This module provides a plugin pattern(Plug-and-Play) solustion.
- No need to edit any file to configure plugin, it can install, uninstall, enable and disable at admin control panel.
- Plugins do not modify project files, it can be uninstall safely.
- Extendable. Can add hooks to any views.
- Encapsulate Yii functions, easy for non-Yii developer to create a plugin

Module Usage
------------

[](#module-usage)

### Install

[](#install)

```
   composer install --prefer-dist zacksleo/yii2-plugin

```

Add these array in the project config (if you have more than one entries,add these in both of them)

```
'components' =>[
    'plugin' => [
        'class' => 'zacksleo\yii2\plugin\components\HookRender'
    ],
],

'modules' => [

    'plugin' => [
        'class' => 'zacksleo\yii2\plugin\Module',
        'layout' => 'layout',
        'layoutPath' => '@vendor/zacksleo/yii2-backend/src/views/layouts', #布局
        'pluginRoot' => '@vendor/moguyun-plugins/', ##放置插件的namespace目录
        'pluginNamespace' => '@moguyun/plugins',  ##放置插件的namespace
    ],
]

```

### Create table

[](#create-table)

```
 yii migrate/up --migrationPath=@zacksleo/yii2/plugin/migrations

```

### Link to plugin control panel

[](#link-to-plugin-control-panel)

The CP url is :

```
$this->createUrl(['/plugin/plugin-manage/index']);

```

### Add hooks in the views

[](#add-hooks-in-the-views)

```
#just add this to the position you want to be hooked
Yii::$app->plugin->render('Hook_Name');   # Name the Hook Position and told it to your plugin developers.

```

---

Plugin Develop
--------------

[](#plugin-develop)

### Create A Plugin

[](#create-a-plugin)

For Create a plugin, you need to inherit the class `Plugin`.

And the class name and class file name should end with the word `Plugin`. For expamle, file `ExamplePlugin.php`:

```
class ExamplePlugin extends Plugin {
    //codes here
}

```

The word `Example` (without word `Plugin`) is the plugin's **identify** (case sensitive). ###Implement The Plugin To implement the plugin and makes it work, you should inherit these method and initialize some properties.

```
class ExamplePlugin extends Plugin {

    public function init() {                    #initialize,config plugin's info, required
        // set plugin's info
        $this->identify = 'Example';            #required, the Unique id for this plugin.
        $this->name = 'Example Plugin';         #required, plugin's name for display.
        $this->version = '1.0';
        $this->description = 'description here';
        $this->copyright = '&copy; Robin &lt;Robin@email.com&gt;';
        $this->website = 'http://example.com';
        $this->icon = 'icon.png'; #max to 72*72, if not set a default icon will display in the admin cp;
    }

    // return hooks array which this plugin want to hook, the value is the method's name
    // for the hook.
    public function hooks(){
        return array(
            //'Hook Position Name' => 'hook method';
            'Hook_Index_Header' => 'header',
        );
    }

    // method for hook
    public function header(){
        // some codes here
        echo 'This will echo a sting at position Hook_Index_Header';
    }

    // If you want to display a page with an url instead of render as a widget,
    // you need to write a method begin with the word "action", the word after
    // "action" is the action's name.
    // e.g.:
    public function actionPage() {
        echo "This action have a url like this (with url rewrite):";
        # domain/plugin/plugin/index
        # ?id=xx&action=xxx
        echo "You_Domain.com/plugin/plugin/index?id=example&action=page";

        #You can create this url by call method 'createUrl'
        echo $this->createUrl('page',array('param'=>'test'));
    }

    public function actionExample(){
        # this action is named with plugin's identify,
        # param $action could be empty or false value
        echo $this->createUrl();
    }

    // If your plugin allow to set configs at the admin control panel
    // You need to inherit this:

    public function admincp() {
        // You can put codes here.
        // Like some inputs
        $this->setSetting('key','value');   # write setting
        echo $this->getSetting('key');      # read setting
    }

    // Here you can put some code at the Installation and Uninstallation
    public function install() {
        //codes here
        $sql = "create `tbl_xxxxxx` .....";     # write sql with a table prefix
        $this->query($sql,'tbl_');              # and pass it at method query
                                                # as default, it is 'tbl_'
        return true; #This method need to return true, or the installation will fail.
    }

    public function uninstall() {
        // just like the method install.
        return true; #This method need to return true, or the uninstallation will fail.
    }

    // Then, you created a simple plugin
    // For advanced usage, see demos
}

```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 57.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~5 days

Total

9

Last Release

3081d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e97b8a6f67b09513e345a128d73a63898ae1ec9f6a6c77234c78b3f16d305d1?d=identicon)[zacksleo](/maintainers/zacksleo)

---

Top Contributors

[![zacksleo](https://avatars.githubusercontent.com/u/3369169?v=4)](https://github.com/zacksleo "zacksleo (27 commits)")[![health901](https://avatars.githubusercontent.com/u/1503105?v=4)](https://github.com/health901 "health901 (20 commits)")

---

Tags

hookspluginyii2yii2-extension

### Embed Badge

![Health badge](/badges/zacksleo-yii2-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/zacksleo-yii2-plugin/health.svg)](https://phpackages.com/packages/zacksleo-yii2-plugin)
```

###  Alternatives

[yiisoft/yii2-app-basic

Yii 2 Basic Project Template

6751.8M8](/packages/yiisoft-yii2-app-basic)[yiisoft/yii2-apidoc

API Documentation generator for the Yii framework 2.0

259709.1k31](/packages/yiisoft-yii2-apidoc)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13725.7k50](/packages/skeeks-cms)[yeesoft/yii2-yee-cms

Yee CMS Based on Yii 2 Advanced Project Template

1464.0k](/packages/yeesoft-yii2-yee-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
