您的位置:首页 > 编程语言 > PHP开发

ThinkPHP使用-自动生成控制器

2017-03-10 00:00 239 查看
ThinkPHP自带了一个功能,使用命令行可以生成一个控制器,控制器包含一些默认的方法(index,create,save,read,edit,update,delete)。

切换到ThinkPHP根目录,application同级的,命令行如下:

cd /var/www/html/thinkphp
php think make:controller demo/Sell

则会生成一个Sell.php的文件,相对应的是资源路由:

Route::resource('order', 'demo/Sell');

主要作用是省了复制粘贴的操作。

生成的代码:

<?php

namespace app\demo\controller;

use think\Controller;
use think\Request;

class Sell extends Controller
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
}

/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}

/**
* 保存新建的资源
*
* @param  \think\Request  $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}

/**
* 显示指定的资源
*
* @param  int  $id
* @return \think\Response
*/
public function read($id)
{
//
}

/**
* 显示编辑资源表单页.
*
* @param  int  $id
* @return \think\Response
*/
public function edit($id)
{
//
}

/**
* 保存更新的资源
*
* @param  \think\Request  $request
* @param  int  $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* 删除指定资源
*
* @param  int  $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ThinkPHP