YII2 modules新增路由访问

前言

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

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

配置config/modules.php

'healthy' => 'backendmoduleshealthyModule',

填写modules请求文件

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

namespace backendmoduleshealthy;

/**
 * workorder module definition class
 */
class Module extends yiiaseModule
{
    /**
     * @inheritdoc
     */
    public $controllerNamespace = 'backendmoduleshealthycontrollers';

    public $defaultRoute = '';

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

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

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

原文地址:https://www.cnblogs.com/mengyilingjian/p/14146711.html