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

黄舟
Libérer: 2023-03-06 10:44:01
original
1826 Les gens l'ont consulté

见证奇迹的时刻到了,我们要 自动生成目录结构 了~这是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'],
    ],
Copier après la connexion

或者,这样:

    // 定义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'],
    ],
Copier après la connexion

的代码,指定好目录结构,和文件 进行自动生成。

看下图:入口文件中 自动生成 自定义目录介绍的写法:

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;);
Copier après la connexion


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;);
Copier après la connexion

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

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



Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!