见证奇迹的时刻到了,我们要 自动生成目录结构 了~这是tp带来的便利~要不然我们要用框架而不是用原生呢~
在线文档:http://www.kancloud.cn/manual/thinkphp5/118021
不方便演示,有兴趣同学区看下开发手册~
我们在 .\build.php 中添加,这样:
// 定义demo模块的自动生成 (按照实际定义的文件名生成)
'demo' => [
'__file__' => ['common.php'],
'__dir__' => ['behavior', 'controller', 'model', 'view'],
'controller' => ['Index', 'Test', 'UserType'],
'model' => ['User', 'UserType'],
'view' => ['index/index'],
],或者,这样:
// 定义index模块的自动生成
'index' => [
'__file__' => ['tags.php', 'user.php', 'hello.php'],
'__dir__' => ['behavior', 'controller', 'model', 'view'],
'controller' => ['Index', 'Test', 'UserType'],
'model' => [],
'view' => ['index/index'],
],
// 定义test模块的自动生成
'test'=>[
'__dir__' => ['behavior','controller','model','widget'],
'controller'=> ['Index','Test','UserType'],
'model' => ['User','UserType'],
'view' => ['index/index','index/test'],
], 的代码,指定好目录结构,和文件 进行自动生成。
立即学习“PHP免费学习笔记(深入)”;
看下图:入口文件中 自动生成 自定义目录介绍的写法:
index.html:
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://www.php.cn/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.php.cn/ )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 应用入口文件 ]
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
/**
* 自动生成目录结构 方法1
*/
// 读取自动生成定义文件
$build = include '../build.php';
// 运行自动生成
\think\Build::run($build);
/**
* 自动生成目录结构 方法2
*/
//\think\Build::module('admin'); 

index.html:
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://www.php.cn/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.php.cn/ )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 应用入口文件 ]
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
/**
* 自动生成目录结构 方法1
*/
//// 读取自动生成定义文件
//$build = include '../build.php';
//// 运行自动生成
//\think\Build::run($build);
/**
* 自动生成目录结构 方法2
*/
\think\Build::module('admin'); 注意,这种方法,不需要对build.php进行操作
以上就是Android程序员学PHP开发(34)-ThinkPHP5.0(6)自动生成-PhpStorm的内容,更多相关内容请关注PHP中文网(www.php.cn)!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号