首頁  >  文章  >  後端開發  >  Android程式設計PHP開發(34)-ThinkPHP5.0(6)自動產生-PhpStorm

Android程式設計PHP開發(34)-ThinkPHP5.0(6)自動產生-PhpStorm

黄舟
黄舟原創
2017-03-03 10:09:381827瀏覽

見證奇蹟的時刻到了,我們要 自動產生目錄結構了~這是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)!




#

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn