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

黄舟
发布: 2023-03-06 10:44:01
原创
1826 人浏览过

见证奇迹的时刻到了,我们要 自动生成目录结构 了~这是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.php.cn/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.php.cn/ )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]

// 定义应用目录
define(&#39;APP_PATH&#39;, __DIR__ . &#39;/../application/&#39;);
// 加载框架引导文件
require __DIR__ . &#39;/../thinkphp/start.php&#39;;

/**
 * 自动生成目录结构 方法1
 */
// 读取自动生成定义文件
$build = include &#39;../build.php&#39;;
// 运行自动生成
\think\Build::run($build);

/**
 * 自动生成目录结构 方法2
 */
//\think\Build::module(&#39;admin&#39;);
登录后复制


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

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(&#39;APP_PATH&#39;, __DIR__ . &#39;/../application/&#39;);
// 加载框架引导文件
require __DIR__ . &#39;/../thinkphp/start.php&#39;;

/**
 * 自动生成目录结构 方法1
 */
//// 读取自动生成定义文件
//$build = include &#39;../build.php&#39;;
//// 运行自动生成
//\think\Build::run($build);

/**
 * 自动生成目录结构 方法2
 */
\think\Build::module(&#39;admin&#39;);
登录后复制

注意,这种方法,不需要对build.php进行操作

 以上就是Android程序员学PHP开发(34)-ThinkPHP5.0(6)自动生成-PhpStorm的内容,更多相关内容请关注PHP中文网(www.php.cn)!



来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!