laravel 路由 RESTful 資源控制器 Route::resource

來源:互聯網
上載者:User
在 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

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.