ThinkPHP5 资源嵌套路由配置方法(可以根据需要实现多层嵌套) - 05
//资源嵌套路由配置方法(可以根据需要实现多层嵌套):
// 更改嵌套资源路由blogs资源的资源变量名为blog_id
Route::resource("blogs","index/Blog",["var"=>["blogs"=>"blog_id"]]);//主表路由
// create GET http://contoso.org/blogs/create
// save POST http://contoso.org/blogs
// edit GET http://contoso.org/blogs/100/edit
// read GET http://contoso.org/blogs/100
// update PUT http://contoso.org/blogs/100
// delete DELETE http://contoso.org/blogs/100
// index GET http://contoso.org/blogs
Route::resource("blogs.comments","index/Comment",["var"=>["blogs"=>"blog_id"]]);//从表路由
// create GET http://contoso.org/blogs/128/comments/create
// save POST http://contoso.org/blogs/128/comments
// edit GET http://contoso.org/blogs/128/comments/32/edit
// read GET http://contoso.org/blogs/128/comments/32
// update PUT http://contoso.org/blogs/128/comments/32
// delete DELETE http://contoso.org/blogs/128/comments/32
// index GET http://contoso.org/blogs/128/comments
// 主表路由生成的路由规则分别是:
// create GET blogs/:blog_id/create
// save POST blogs
// edit GET blogs/:blog_id/edit
// read GET blogs/:blog_id
// update PUT blogs/:blog_id
// delete DELETE blogs/:blog_id
// index GET blogs
// 从表路由生成的路由规则分别是:
// create GET blogs/:blog_id/comments/create
// save POST blogs/:blog_id/comments
// edit GET blogs/:blog_id/comments/:id/edit
// read GET blogs/:blog_id/comments/:id
// update PUT blogs/:blog_id/comments/:id
// delete DELETE blogs/:blog_id/comments/:id
// index GET blogs/:blog_id/comments
<?php
namespace appindexcontroller;
use thinkController;
use thinkRequest;
class Blog extends Controller
{
/**
* 显示资源列表
*
* @return hinkResponse
*/
public function index()
{
echo "index";
}
/**
* 显示创建资源表单页.
*
* @return hinkResponse
*/
public function create()
{
echo "create";
}
/**
* 保存新建的资源
*
* @param hinkRequest $request
* @return hinkResponse
*/
public function save(Request $request)
{
echo "save";
}
/**
* 显示指定的资源
*
* @param int $blog_id
* @return hinkResponse
*/
public function read($blog_id)
{
echo "read"." ".$blog_id;
}
/**
* 显示编辑资源表单页.
*
* @param int $blog_id
* @return hinkResponse
*/
public function edit($blog_id)
{
echo "edit"." ".$blog_id;
}
/**
* 保存更新的资源
*
* @param hinkRequest $request
* @param int $blog_id
* @return hinkResponse
*/
public function update(Request $request, $blog_id)
{
echo "update"." ".$blog_id;
}
/**
* 删除指定资源
*
* @param int $blog_id
* @return hinkResponse
*/
public function delete($blog_id)
{
echo "delete"." ".$blog_id;
}
}
<?php
namespace appindexcontroller;
use thinkController;
use thinkRequest;
class Comment extends Controller
{
public function create($blog_id)
{
echo "method is create, this is a Comment"." blog_id=".$blog_id;
}
public function save(Request $request,$blog_id)
{
echo "method is save, this is a Comment"." blog_id=".$blog_id;
}
public function read($id, $blog_id)
{
echo "method is read, this is a Comment"." id =".$id." blog_id=".$blog_id;
}
public function edit($id, $blog_id)
{
echo "method is edit, this is a Comment"." id =".$id." blog_id=".$blog_id;
}
public function update(Request $request, $id, $blog_id)
{
echo "method is update, this is a Comment"." id =".$id." blog_id=".$blog_id;
}
public function delete($id, $blog_id)
{
echo "method is delete, this is a Comment"." id =".$id." blog_id=".$blog_id;
}
public function index($blog_id)
{
echo "method is index, this is a Comment"." blog_id=".$blog_id;
}
}
- 上一篇: ThinkPHP5.1 @[模块/控制器/]操作
- 下一篇: ThinkPHP5 行为和钩子 - 01