thinkphp5.1 restfull资源路由快速创建

1,我的tp5安装的根目录为:tp5.1

命令行先进入到tp5根目录

运行命令:php think 看到下面有build,clear,help,list,run,make等命令说明

我们测试一下make命令:make:controller 。提示:Controller created successfully。

看下项目文件发生什么变化:在模块esource下多出了MakeDemo.php控制器文件,并且已经有了默认类方法。

这个文件是restfull资源默认的初始文件。

创建 资源路由:Route::resource('stone','resource/MakeDemo');

这样:http://domain/stone

扫描二维码关注公众号,回复: 3025925 查看本文章

便可以有post,get,put,delete等请求方式来访问这些类方法了

<?php

namespace app\resource\controller;

use think\Controller;
use think\Request;

class MakeDemo 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)
    {
        //
    }
}

猜你喜欢

转载自blog.csdn.net/haocaicai/article/details/82188273
今日推荐