标签:
看了下教程,总结了下,大概分两种
一般的controller
restful的controller
单独绑定action的route为
Route::get(‘user/{id}‘, ‘UserController@showProfile‘);
一般的controller
./artisan controller:make TestController Route::controller(‘test‘, ‘TestController‘);
TestController.php
<?php class TestController extends \BaseController { public function getShow() { $data = Input::all(); return $data; } }
action的前缀get,post,any对应是请求模式
访问的url
http://127.0.0.1:8888/testApp/public/test/show?aa=1&bb=2&cc=3
输出
{"aa":"1","bb":"2","cc":"3"}
restful的controller,设计理念是对于某个对象进行curd,只是这个操作通过url表现,抽象出来了
./artisan controller:make BookController Route::resource(‘book‘, ‘BookController‘);
修改BookController里面的
public function show($id) { return "show " . $id; }
url测试
http://127.0.0.1:8888/testApp/public/book/book1
具体restful的路径可以参考laravel的英文文档,中文的目测没有。。。略显蛋疼
Verb | Path | Action | Route Name |
---|---|---|---|
GET | /resource | index | resource.index |
GET | /resource/create | create | resource.create |
POST | /resource | store | resource.store |
GET | /resource/{resource} | show | resource.show |
GET | /resource/{resource}/edit | edit | resource.edit |
PUT/PATCH | /resource/{resource} | update | resource.update |
DELETE | /resource/{resource} | destroy | resource.destroy |
用的时候,常规controller应该是对于多种model和逻辑混合的情况,单独restful的controller类似独立model的curd,在controller层面实现了解耦
标签:
原文地址:http://www.cnblogs.com/ziyouchutuwenwu/p/4268535.html