见证奇迹的时刻到了,我们要 自动生成目录结构 了~这是TP带来的便利~要不然我们要用框架而不是用原生呢~
在线文档:http://www.kancloud.cn/manual/thinkphp5/118021
1、命令行自动生成
不方便演示,有兴趣同学区看下开发手册~
2、添加自动生成代码
我们在 .\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'], ],
的代码,指定好目录结构,和文件 进行自动生成。
看下图:入口文件中 自动生成 自定义目录介绍的写法:
index.html:
<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2016 http://www.gaodaima.com/ All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.gaodaima.com/ )// +----------------------------------------------------------------------// | Author: liu21st <[email protected]>// +----------------------------------------------------------------------// [ 应用入口文件 ]// 定义应用目录define('APP_PATH', __DIR__ . '/../application/');// 加载框架引导文件require __DIR__ . '/../thinkphp/start.php';/** * 自动生成目录结构 方法1 */// 读取自动生成定义文件$build = include '../build.php';// 运行自动生成\think\Build::run($build);/** * 自动生成目录结构 方法2 *///\think\Build::module('admin');
3、自动生成默认目录结构和文件:
index.html:
<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2016 http://www.gaodaima.com/ All rights <strong>+本文来源gao@daima#com搞(%代@#码网</strong><pre>搞代gaodaima码
reserved.// +———————————————————————-// | Licensed ( http://www.gaodaima.com/ )// +———————————————————————-// | Author: liu21st <[email protected]>// +———————————————————————-// [ 应用入口文件 ]// 定义应用目录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的内容,更多相关内容请随时关注我们网站!