thinkphp5.0

由于刚开始接触thinkphp5.0,还不知道怎么创建模块,看了官方的文档,将怎样创建应用模块的整个流程总结如下,以方便以后学习。

thinkphp5.0是用命令行创建应用模块的。首先需要确保你电脑中的php.exe已经加入到系统环境变量Path;你如果不会添加系统环境变量,请根据如下流程操作:

加入系统环境变量方式如下:win7系统中在桌面单击鼠标右键:  计算机->属性->高级系统设置->环境变量,  会弹出对话框‘系统属性’,点击最下边的滚动条,找到Path,双击,会弹出对话框‘编辑系统变量’,然后在变量值最后输入: 例如:;C:\phpStudy\php54n  也就是; 加上你php.exe所在目录,注意:如果系统变量值在你加入之前最后没有;,这个;必须加入。 然后点击最下边的‘新建按钮’,在弹出框中的变量名中输入:PHPRC  变量值中输入:例如:C:\phpStudy\php54n  就是你的php.ini所在目录。点击确定。至此系统环境变量完成。


thinkphp5.0应用的命令行入口文件是根目录的think文件;要执行命令行首先点击‘运行’输入cmd,然后切换的本项目的think文件所在目录中,执行命令  php think  会显示当前支持的所有指令:如下

>php think
Think Console version 0.1

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -V, --version         Display this console version
  -q, --quiet           Do not output any message
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  build              Build Application Dirs
  help               Displays help for a command
  list               Lists commands
 make
  make:controller    Create a new controller class
  make:model         Create a new model class
 optimize
  optimize:autoload  Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.
为了生成新的应用模块;在Application下边先创建个文件bulid.php;

当前文件内容如下:

return [
    // 定义test模块的自动生成
    'test' => [
        '__dir__'    => ['controller', 'model', 'view'],
        'controller' => ['User', 'UserType'],
        'model'      => ['User', 'UserType'],
        'view'       => ['index/index', 'index/test'],
    ],
];
然后在命令行下边执行成功后会出现:
>php think build
Successed

在Application下边会出现test

你可能感兴趣的:(thinkphp5.0)