json [示例]在craft3插件中使用Controller

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json [示例]在craft3插件中使用Controller相关的知识,希望对你有一定的参考价值。

<?php

namespace my\plugin;


use craft\events\RegisterTemplateRootsEvent;
use craft\events\RegisterUrlRulesEvent;
use craft\web\UrlManager;
use craft\web\View;
use yii\base\Event;

class Plugin extends \craft\base\Plugin
{
	public static $plugin;

	public $schemaVersion = '1.0.0';

	public function init()
	{
		parent::init();
		self::$plugin = $this;

		Event::on(UrlManager::class,
			UrlManager::EVENT_REGISTER_SITE_URL_RULES,
			function (RegisterUrlRulesEvent $event) {
				$event->rules['my'] = 'myplugin/top';
			}
		);

		Event::on(UrlManager::class,
			UrlManager::EVENT_REGISTER_CP_URL_RULES,
			function (RegisterUrlRulesEvent $event) {
				$event->rules['my'] = 'myplugin/top/admin';
			});

		Event::on(View::class,
			View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,
			function (RegisterTemplateRootsEvent $event) {
				$event->roots['myplugin'] = __DIR__ . '/templates';
			});
	}
}
<?php

namespace my\plugin\controllers;


use craft\web\Controller;

class TopController extends Controller
{
	public function actionIndex() {
		return 'my plugin';
	}

	public function actionHoge()
	{
		$this->requirePermission('admin');
		return 'my plugin admin';
	}
}
{
  "name": "user/myplugin",
  "type": "craft-plugin",
  "authors": [
    {
      "name": "User Name",
      "email": "user@mail.address"
    }
  ],
  "require": {
    "craftcms/cms": "^3.0.0"
  },
  "autoload": {
    "psr-4": {
      "my\\plugin\\": "src/"
    }
  },
  "extra": {
    "name": "myplugin",
    "handle": "myplugin"
  }
}

以上是关于json [示例]在craft3插件中使用Controller的主要内容,如果未能解决你的问题,请参考以下文章

json WordPress插件的示例Composer文件。

json Packer社区插件 - Windows 2012安装示例

idea插件(支持动态识别泛型的)JavaBean转JSON插件

idea插件(支持动态识别泛型的)JavaBean转JSON插件

idea插件(支持动态识别泛型的)JavaBean转JSON插件

为 jQuery 日历编码 JSON