tp6_003多应用配置

 

1、安装多应用模式扩展think-multi-app

 
composer require topthink/think-multi-app
 

2、在app目录新建 admin 和 index和 api 目录

 
或者通过 指令创建更快速
php think build index
php think build admin
php think build api
 
 

3、将原本的app目录下面的controller目录文件复制到 index目录和admin目录和 api目录下

(说明:通过手工创建的目录执行该操作,通过指令无需操作)
 
然后将app目录下的controller删除(重要)
 
最终目录格式如下:我创建了3个应用
 

 

 
特别说明 特别说明 特别说明:
不要把以下文件放到子应用目录中了,放进去就有意想不到的bug
app/AppService.php
app/BaseController.php
app/ExceptionHandle.php
app/provider.php
app/Request.php
app/service.php
 
 

5、访问index项目

http://tp6.cn/index.php/index
 

6、访问admin应用

http://tp6.cn/index.php/admin
 
访问 api应用
http://tp6.cn/index.php/api/
 

7、隐藏 index.php

 
a、nginx url重写
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
 
隐藏后:访问index项目
http://tp6.cn/index/index/
 
隐藏后:访问admin项目
http://tp6.cn/admin/index/
 
隐藏后:访问api项目
http://tp6.cn/api/index/

但行好事,莫问前程!

本文来自博客园,作者:yangphp,转载请注明原文链接:https://www.cnblogs.com/ypeih/p/15390934.html

原文地址:https://www.cnblogs.com/ypeih/p/15390934.html