首页 > 技术文章 > YII2 modules新增路由访问

mengyilingjian 2020-12-16 22:38 原文

前言

tips:如果本文对你有用,请爱心点个赞,提高排名,让这篇文章帮助更多的人。谢谢大家!比心❤~
如果解决不了,可以在文末加我微信,进群交流。

此处将一个心跳检测的接口作为一个modules举例

配置config/modules.php

'healthy' => 'backend\modules\healthy\Module',

填写modules请求文件

  1. 在目录backend/modules/healthy/创建Module.php,写入以下内容
<?php

namespace backend\modules\healthy;

/**
 * workorder module definition class
 */
class Module extends \yii\base\Module
{
    /**
     * @inheritdoc
     */
    public $controllerNamespace = 'backend\modules\healthy\controllers';

    public $defaultRoute = '';

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
    }
}
  1. 在目录backend/modules/healthy/controllers创建HeartbeatController.php文件,写入以下内容
<?php
namespace backend\modules\healthy\controllers;
use yii\web\Controller;

class HeartbeatController extends Controller {
    public function actionCheck(){
        echo 'App heartbeat check.';exit(200);
    }
}
  1. 使用postman请求

有问题请添加个人微信:【mengyilingjian】,进群一起技术讨论。添加时请备注来意,谢谢!
在这里插入图片描述

推荐阅读