ThinkPHP5.1资源控制器Blog简单案例,使用路由,开启了强制路由限制,在postman上使用了接口调用,也是参考了官网的简单案例,实现了增删改查,再简单的必须熟练,效率才能提上去。
ThinkPHP5.1资源控制器Blog简单案例,使用路由,开启了强制路由限制,在postman上使用了接口调用,也是参考了官网的简单案例,实现了增删改查,再简单的必须熟练,效率才能提上去。
<?php
/*
* @Author: your name
* @Date: 2021-04-10 11:15:10
* @LastEditTime: 2021-04-21 17:44:36
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \thinkphp5.1.4\application\api\controller\Blog.php
*/
namespace app\api\controller;
use think\Controller;
use think\Request;
use app\api\services\Blogs;
class Blog extends Controller
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
$result = (new Blogs())->lists();
$this->result($result, 200, '博文列表', 'json',);
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create(Request $request)
{
//
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
$data = $request->post();
$result = Blogs::create($data);
$this->result($result, 200, '新建博文成功', 'json',);
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
$result = Blogs::read($id);
$this->result($result, 200, '博文详情', 'json',);
}
/**
* 显示编辑资源表单页.
*
* @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)
{
$data = $request->post();
$result = Blogs::save($id, $data);
$this->result($result, 200, '更新博文成功', 'json',);
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
$result = Blogs::delete($id);
$this->result($result, 200, '博文删除', 'json',);
}
}
https://www.fxzbcn.com/html/thinkphp5/thinkphp51ziyuankongzhiqiBlogjiandananlizhipostman.html
https://www.fxzbcn.com/html/thinkphp5/thinkphp51ziyuankongzhiqiBlogjiandananlizhikongzhiqi.html
https://www.fxzbcn.com/html/thinkphp5/thinkphp51ziyuankongzhiqiBlogjiandananlizhifuwucengfangfa.html
https://www.fxzbcn.com/html/thinkphp5/thinkphp51ziyuankongzhiqiBlogjiandananlizhimoxingfangfa.html
转载注明:
感谢博主,喝杯咖啡~
感谢博主,喝杯咖啡~
还没有人发表评论