42 THINKPHP的资源路由

自动创建带有7个方法的控制器

php think make:controller blog222

给控制器blog222加载自动资源路由

//资源路由

Route::resource('blog222','blog222');

ok
完成了

修改一下blog222控制器
进行测试

<?php

namespace app\controller;

use think\Controller;
use think\Request;

class blog222 extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return 'this is blog222.index';
    }

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

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

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

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

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

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        return 'this is blog222.delete'.$id;
    }
}

可以直接在浏览器测试。read方法

利用ajax测试delete方法,update方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    {js href="__JS__/jquery-3.5.1.js"/}
</head>
<body>
<form name="test">
    <input type="button" id="sent" value="发送"> </form>


</body>

<script>
    //  加载dom元素
    $(function () {
        $('#sent').click(function () {
            $.ajax({
                type: "Delete",
                url: "http://localhost:8888/blog222/10",
                success:function (res) {
                    console.log(res)
                }

            });
        })
    })

</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值