tp5.1 命令行访问

        安装Thinkphp 5.1

composer create-project topthink/think=5.1.* www.tp5.com

        查看应用配置(config/app.php),是否支持多模块

'app_multi_module' => true,

        自动生成多应用目录结构

PS D:\web\www.tp5.com> php think build --module home
Successed

PS D:\web\www.tp5.com> php think build --module admin
Successed


        1. home 默认Index 控制器

        application/home/controller/Index.php

<?php
namespace app\home\controller;

class Index
{
    public function index()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改(2006-2018) - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }
}

    2. home目录 controller 新建 目录 test, 新建 Api 控制器

        application/home/controller/test/Api.php

<?php
namespace app\home\controller\test;

class Api
{
    public function index()
    {
        return 'api';
    }
}

        application/home/controller/test/ApiTest.php

<?php
namespace app\home\controller\test;

class ApiTest
{
    public function index()
    {
        return 'api-test';
    }
}

    3. 命令行访问

访问 home 默认控制器Index
PS D:\web\www.tp5.com> php public/index.php home/Index/index


访问多级目录
PS D:\web\www.tp5.com> php public/index.php home/test.api/index

PS D:\web\www.tp5.com> php public/index.php home/test.api_test/index
api-test

冷暖自知一抹茶ck




附录:

        多级控制器

冷暖自知一抹茶ck
请先登录后发表评论
  • 最新评论
  • 总共0条评论