Giter Site home page Giter Site logo

generator-thinkphp's Introduction

Thinkphp Generator | Thinkphp 生成器

利用yeoman自动构建thinkphp应用 - 通过命令行自动创建应用以及 Controller/Model/View.

English Doc

使用方法

安装 Composer 关于 composer

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

安装 yo and generator-thinkphp 关于 Yeoman

npm install -g yo generator-thinkphp

cd 进入到你的工作文件夹以进行下一步操作:

cd [workPlace]

workPlace是指你平时写代码的文件夹

输入 yo thinkphp 来生成应用,根据指引输入,你可以自定义应用名称,如果你未安装 Composer 会有提示是否自动安装:

yo thinkphp

输入 cd [appName] 进入你的应用目录,开始一下步操作:

cd [appName]

appName是指你自定义应用的名称

自动生成器

已支持的生成器:

App

创建新的 ThinkPHP 应用并使用 Composer.

Example:

yo thinkphp

Controller

为你的应用自动生成新的Controller. 例如 yo thinkphp:controller [classedName] [spaceName].

classedName 为必选项,不能为空.

spaceName 默认为 Home ,可选项.

Example:

yo thinkphp:controller Index Home

此命令生成 Application/Home/Controller/IndexController.class.php:

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

    public function index(){
    	//
        $this->display();
    }

}

以及 Application/Home/View/Index/index.html:

<extend name="base" />
<block name="content">
	<h1>Index</h1>
</block>

以及 Application/Home/View/Index/base.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Home</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
    <block name="content"></block>
</body>
</html>

Model

和Controller命令基本一样, 为你的应用自动生成新的Model.

Example:

yo thinkphp:model User Home

生成 Application/Home/Model/UserModel.class.php:

<?php
namespace Home\Model;
use Think\Model;
class UserModel extends Model {
	//
    protected $tableName = 'User';

}

Space

为你的应用生成新的命名空间. 命名空间是指thinkphp应用中例如Home/Admin等文件夹

Example:

yo thinkphp:space Admin

生成 Application/Admin 文件夹以及初始内容.

  • Admin
    • Common
    • Conf
    • Controller
    • Model
    • View
    • index.html

Serve

运行本地的php测试服务器,此功能利用php自带的测试服务器实现.

Example:

yo thinkphp:serve

你的测试服务器运行在 127.0.0.1:3000.

关于

Thinkphp的命令行自动构建工具,类似 Laravelphp artisan

许可证

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.