在 routes.php 定義了 一個 RESTful
Route::resource('com','ComController');
在 ComController.php
裡面 定義了如下方法
public function index() { return "index"; } public function show() { return "show"; } public function edit($id) { return "edit".$id; } public function del($id) { return "del".$id; }
$id 都會報錯
有什麼好的方法 可以 定義好一個路由對應一個控制器
控制器下面的方法 不用再路由上定義呢
Route::controllers([ 'com' => 'ComController',]);
用此路由 怎麼傳 $id 呢
路由的 RESTful 方法 和 controllers 有什麼區別呢
求大神指點一下啊
回複內容:
在 routes.php 定義了 一個 RESTful
Route::resource('com','ComController');
在 ComController.php
裡面 定義了如下方法
public function index() { return "index"; } public function show() { return "show"; } public function edit($id) { return "edit".$id; } public function del($id) { return "del".$id; }
$id 都會報錯
有什麼好的方法 可以 定義好一個路由對應一個控制器
控制器下面的方法 不用再路由上定義呢
Route::controllers([ 'com' => 'ComController',]);
用此路由 怎麼傳 $id 呢
路由的 RESTful 方法 和 controllers 有什麼區別呢
求大神指點一下啊
你的需求應該是這個:
http://laravel.com/docs/5.0/controllers#implicit-controllers
routes.php
phpRoute::controller('users', 'UserController');
UserController.php
php// GET http://domain/users/indexpublic function getIndex() {}// POST http://domain/users/profile/3public function postProfile($id) {}// DELETE http://domain/users/user/3public function deleteUser($id) {}
動詞 路徑 行為 路由名稱
GET /photo 索引 photo.index
GET /photo/create 建立 photo.create
POST /photo 儲存 photo.store
GET /photo/{photo} 顯示 photo.show
GET /photo/{photo}/edit 編輯 photo.edit
PUT/PATCH /photo/{photo} 更新 photo.update
DELETE /photo/{photo} 刪除 photo.destroy
你注意看文檔,它已經給你規定好了路勁
比如index
restfull 應該是:http://{domain}/photo,而不是:http://{domain}/photo/index