我使用的應用程序以下/ routes.php文件試圖路由到一個RESTful控制器:laravel 4路線::控制器()方法返回NotFoundHttpException
Route::controller('register', 'RegisterController');
Route::get('/', '[email protected]');
在我的應用程序/控制器/ RegisterController.php文件我已經添加了以下情況:
<?php
class RegisterController extends BaseController
{
public function getRegister()
{
return View::make('registration');
}
public function postRegister()
{
$data = Input::all();
$rules = array(
'first_name' => array('alpha', 'min:3'),
'last_name' => array('alpha', 'min:3'),
'company_name' => array('alpha_num'),
'phone_number' => 'regex:[0-9()\-]'
);
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
return 'Data was saved.';
}
return Redirect::to('register')->withErrors($validator);
}
}
我收到以下錯誤:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
當我運行PHP的工匠航線終端獲得:
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| | GET /register/register/{v1}/{v2}/{v3}/{v4}/{v5} | | [email protected] | | |
| | POST /register/register/{v1}/{v2}/{v3}/{v4}/{v5} | | [email protected] | | |
| | GET /register/{_missing} | | [email protected] | | |
| | GET/ | | [email protected] | | |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
我不明白爲什麼註冊是顯示兩次在URI和第二GET動作失蹤,爲什麼我收到此錯誤。
完美的作品!感謝您的快速和有見地的反應。我想我需要研究使用Route :: resource()vs Route :: controller()的區別。乾杯! –
@GeekyGoon如果你喜歡,請檢查我的一些類似的答案在這裏http://stackoverflow.com/questions/19196636/laravel-restful-controller-parameters/19196884#19196884和http://stackoverflow.com/questions/19190389/ laravel-4-remove-index-on-default-getindex-controller-function/19193669#19193669然後http://stackoverflow.com/questions/19124018/laravel-retrieving-data-from-rest-api/19132837#19132837 – devo
如果你想去'Route :: controller('register','RegisterController')'的方式,你可以使用函數名'getIndex'和'postIndex'來獲得相同的結果。 請參閱:[Restful-controllers](http://laravel.com/docs/controllers#restful-controllers) – tharumax