tp5.0自动生成模块

tp5和tp3不同,tp5的目录生成依赖build.php文件。模块生成方法如下:

a、需要在入口文件Public/index.php最后加以下两句:

// 读取自动生成定义文件
$build = include '../build.php';	//若报错请尝试改成$build = include '/../build.php';
// 运行自动生成
\think\Build::run($build);

注意: 开始用的是 $build = include ‘/…/build.php’; 但是报 ‘页面错误!请稍后再试~’ 的错误,头一天在另一台电脑上是完全没问题的;后来将config.php中的 ‘show_error_msg’ => false 改成 true,显示报错信息为 “include(/…/build.php): failed to open stream: No such file or directory”,发现是路径问题,遂改将路径成上面代码即可正常生成。

b、在根目录build.php文件中配置以下内容:

return [
    // 生成运行时目录
    '__file__' => ['common.php'],

    // 定义index模块的自动生成
    'index'    => [
        '__file__'   => ['common.php'],
        '__dir__'    => ['behavior', 'controller', 'model', 'view'],
        'controller' => ['Index', 'Test', 'UserType'],
        'model'      => [],
        'view'       => ['index/index'],
    ],
    // 其他更多的模块定义,复制上方index模块并修改即可,如添加admin模块
    'admin'     => [
        '__file__'   => ['common.php'],
        '__dir__'    => ['behavior', 'controller', 'model', 'view'],
        'controller' => ['Index', 'Test', 'UserType'],
        'model'      => ['User', 'UserType'],
        'view'       => ['index/index'],
    ],
];

c、在浏览器中访问public目录,即可生成index和admin模块。

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值