Android programmers learn PHP development (34)-ThinkPHP5.0 (6) automatically generated-PhpStorm

黄舟
Release: 2023-03-06 10:44:01
Original
1879 people have browsed it

The time to witness the miracle has arrived, we have to automatically generate the directory structure~This is the convenience brought by TP~Otherwise we have to use a framework instead of native~
Online documentation: http:// www.kancloud.cn/manual/thinkphp5/118021

1. The command line automatically generates

which is not convenient for demonstration. If you are interested, please take a look at the development manual~

2. Add the automatically generated code

##We are here.\ Build.php, like this:

    // 定义demo模块的自动生成 (按照实际定义的文件名生成)
    'demo'     => [
        '__file__'   => ['common.php'],
        '__dir__'    => ['behavior', 'controller', 'model', 'view'],
        'controller' => ['Index', 'Test', 'UserType'],
        'model'      => ['User', 'UserType'],
        'view'       => ['index/index'],
    ],
Copy after login

Or, like this:

    // 定义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'],
    ],
Copy after login

code, specify the directory structure, and automatically generate files.

Look at the picture below: How to automatically generate a custom directory introduction in the entry file:

##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;);
Copy after login


3. Automatically generate the default directory structure and files:

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;);
Copy after login

Note that in this method, build.php does not need to be operated
The above is the content of Android programmers learning PHP development (34) - ThinkPHP5.0 (6) automatically generates - PhpStorm. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template