{"id":15686194,"url":"https://github.com/zacksleo/yii2-plugin","last_synced_at":"2025-09-07T22:44:56.994Z","repository":{"id":57089066,"uuid":"78853117","full_name":"zacksleo/yii2-plugin","owner":"zacksleo","description":"👍 yii2 plugin module, yii2 plugin system, yii2 hook system","archived":false,"fork":false,"pushed_at":"2018-01-16T10:12:04.000Z","size":88,"stargazers_count":9,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-09T15:10:36.452Z","etag":null,"topics":["hooks","plugin","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zacksleo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-13T13:48:25.000Z","updated_at":"2019-09-30T01:20:53.000Z","dependencies_parsed_at":"2022-08-20T16:00:41.765Z","dependency_job_id":null,"html_url":"https://github.com/zacksleo/yii2-plugin","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/zacksleo/yii2-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zacksleo","download_url":"https://codeload.github.com/zacksleo/yii2-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksleo%2Fyii2-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274107989,"owners_count":25223473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hooks","plugin","yii2","yii2-extension"],"created_at":"2024-10-03T17:35:39.171Z","updated_at":"2025-09-07T22:44:56.968Z","avatar_url":"https://github.com/zacksleo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Plugin Module\n\n[![Latest Stable Version](https://poser.pugx.org/zacksleo/yii2-plugin/version)](https://packagist.org/packages/zacksleo/yii2-plugin)\n[![Total Downloads](https://poser.pugx.org/zacksleo/yii2-plugin/downloads)](https://packagist.org/packages/zacksleo/yii2-plugin)\n[![License](https://poser.pugx.org/zacksleo/yii2-plugin/license)](https://packagist.org/packages/zacksleo/yii2-plugin)\n\nLanguages: [English](#) [中文](https://github.com/zacksleo/yii2-plugin/blob/master/README_cn.md)\n\n---\n![cp](http://i.minus.com/ibnW5OhPBsUboA.jpg)\n\n## FEATURES\n* This module provides a plugin pattern(Plug-and-Play) solustion.\n* No need to edit any file to configure plugin, it can install, uninstall, enable and disable at admin control panel.\n* Plugins do not modify project files, it can be uninstall safely.\n* Extendable. Can add hooks to any views.\n* Encapsulate Yii functions, easy for non-Yii developer to create a plugin\n\n## Module Usage\n\n### Install\n\n```\n   composer install --prefer-dist zacksleo/yii2-plugin   \n```   \n\nAdd these array in the project config (if you have more than one entries,add these in both of them)\n    \n    'components' =\u003e[\n        'plugin' =\u003e [\n            'class' =\u003e 'zacksleo\\yii2\\plugin\\components\\HookRender'\n        ],\n    ],\n    \n    'modules' =\u003e [\n    \n        'plugin' =\u003e [\n            'class' =\u003e 'zacksleo\\yii2\\plugin\\Module',\n            'layout' =\u003e 'layout',\n            'layoutPath' =\u003e '@vendor/zacksleo/yii2-backend/src/views/layouts', #布局\n            'pluginRoot' =\u003e '@vendor/moguyun-plugins/', ##放置插件的namespace目录\n            'pluginNamespace' =\u003e '@moguyun/plugins',  ##放置插件的namespace\n        ],  \n    ]\n\n\n### Create table\n\n```\n yii migrate/up --migrationPath=@zacksleo/yii2/plugin/migrations\n```\n\n### Link to plugin control panel\nThe CP url is :\n    \n    $this-\u003ecreateUrl(['/plugin/plugin-manage/index']);\n\n### Add hooks in the views\n\n    #just add this to the position you want to be hooked\n    Yii::$app-\u003eplugin-\u003erender('Hook_Name');   # Name the Hook Position and told it to your plugin developers. \n\n---\n\n## Plugin Develop\n\n### Create A Plugin\nFor Create a plugin, you need to inherit the class `Plugin`.\n\nAnd the class name and class file name should end with the word `Plugin`.\nFor expamle, file `ExamplePlugin.php`:\n    \n    class ExamplePlugin extends Plugin {\n        //codes here\n    }\nThe word `Example` (without word `Plugin`) is the plugin's __identify__ (case sensitive).\n###Implement The Plugin\nTo implement the plugin and makes it work, you should inherit these method and initialize some properties.\n\n    class ExamplePlugin extends Plugin {\n        \n        public function init() {                    #initialize,config plugin's info, required\n            // set plugin's info\n            $this-\u003eidentify = 'Example';            #required, the Unique id for this plugin.\n            $this-\u003ename = 'Example Plugin';         #required, plugin's name for display.\n            $this-\u003eversion = '1.0';\n            $this-\u003edescription = 'description here';\n            $this-\u003ecopyright = '\u0026copy; Robin \u0026lt;Robin@email.com\u0026gt;';\n            $this-\u003ewebsite = 'http://example.com';   \n            $this-\u003eicon = 'icon.png'; #max to 72*72, if not set a default icon will display in the admin cp;\n        }\n        \n        // return hooks array which this plugin want to hook, the value is the method's name\n        // for the hook.\n        public function hooks(){\n            return array(\n                //'Hook Position Name' =\u003e 'hook method';\n                'Hook_Index_Header' =\u003e 'header',\n            );\n        }\n        \n        // method for hook\n        public function header(){\n            // some codes here\n            echo 'This will echo a sting at position Hook_Index_Header';\n        }\n        \n        // If you want to display a page with an url instead of render as a widget,\n        // you need to write a method begin with the word \"action\", the word after \n        // \"action\" is the action's name.\n        // e.g.:\n        public function actionPage() {\n            echo \"This action have a url like this (with url rewrite):\";\n            # domain/plugin\u003cModule\u003e/plugin\u003ccontroller name\u003e/index\u003crouter action name\u003e\n            # ?id=xx\u003cplugin identify\u003e\u0026action=xxx\u003caction name\u003e\n            echo \"You_Domain.com/plugin/plugin/index?id=example\u0026action=page\";\n\n            #You can create this url by call method 'createUrl'\n            echo $this-\u003ecreateUrl('page',array('param'=\u003e'test'));\n        }\n\n        public function actionExample(){\n            # this action is named with plugin's identify,\n            # param $action could be empty or false value\n            echo $this-\u003ecreateUrl();\n        }      \n\n        // If your plugin allow to set configs at the admin control panel\n        // You need to inherit this:\n        \n        public function admincp() {\n            // You can put codes here.\n            // Like some inputs\n            $this-\u003esetSetting('key','value');   # write setting\n            echo $this-\u003egetSetting('key');      # read setting\n        }\n        \n        // Here you can put some code at the Installation and Uninstallation\n        public function install() {\n            //codes here\n            $sql = \"create `tbl_xxxxxx` .....\";     # write sql with a table prefix \n            $this-\u003equery($sql,'tbl_');              # and pass it at method query\n                                                    # as default, it is 'tbl_'\n            return true; #This method need to return true, or the installation will fail.\n        }\n        \n        public function uninstall() {\n            // just like the method install.\n            return true; #This method need to return true, or the uninstallation will fail.\n        }\n        \n        // Then, you created a simple plugin\n        // For advanced usage, see demos\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzacksleo%2Fyii2-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzacksleo%2Fyii2-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzacksleo%2Fyii2-plugin/lists"}