Android程序员学PHP开发(34)-ThinkPHP5.0(6)自动生成-PhpStorm

来源:互联网 发布:c语言必读书籍 编辑:程序博客网 时间:2024/06/05 00:59
转载请注明出处:http://blog.csdn.net/iwanghang/
觉得博文有用,请点赞,请评论,请关注,谢谢!~

见证奇迹的时刻到了,我们要 自动生成目录结构 了~这是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://thinkphp.cn All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | 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');

3、自动生成默认目录结构和文件:

index.html:

<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | 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进行操作




转载请注明出处:http://blog.csdn.net/iwanghang/



欢迎移动开发爱好者交流
沈阳或周边城市公司有意开发Android,请与我联系
联系方式

微信:iwanghang
QQ:413711276
邮箱:iwanghang@qq.com



觉得博文有用,请点赞,请评论,请关注,谢谢!~

1 0
原创粉丝点击