laravel 4路由::控制器()方法返回NotFoundHttpException。

[英]laravel 4 Route::controller() method returns NotFoundHttpException


I am trying to route to a RESTful controller using the following in app/routes.php:

我正在尝试在app/routes.php中使用以下方法来访问一个RESTful控制器。

Route::controller('register', 'RegisterController');

Route::get('/', 'HomeController@showWelcome');

In my app/controllers/RegisterController.php file I have added the following:

在我的应用程序/控制器/ RegisterController。我添加了以下内容:

<?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);
    }
}

I am getting the following error:

我得到了以下错误:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Symfony \组件\ HttpKernel \ Exception \ NotFoundHttpException。

When I run php artisan routes in terminal I get:

当我在终端运行php artisan路由时:

+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| Domain | URI                                              | Name | Action                     | Before Filters | After Filters |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
|        | GET /register/register/{v1}/{v2}/{v3}/{v4}/{v5}  |      | Register@getRegister       |                |               |
|        | POST /register/register/{v1}/{v2}/{v3}/{v4}/{v5} |      | Register@postRegister      |                |               |
|        | GET /register/{_missing}                         |      | Register@missingMethod     |                |               |
|        | GET /                                            |      | HomeController@showWelcome |                |               |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+

I don't understand why register is showing twice in the URI and the second GET action is missing and why I am getting this error.

我不明白为什么寄存器在URI中显示两次,第二个GET操作丢失了,为什么会出现这个错误。

2 个解决方案

#1


5  

If you are using RESTful API, the best way is in your route,

如果您使用的是RESTful API,最好的方法是在您的路径中,

Route::resource('register', 'RegisterController');

And change your public function getRegister() to public function index() and public function postRegister() to public function store()

将您的公共函数getRegister()改为public function index()和public function postRegister()到public function store()

Then the index() can be access using GET http://localhost/laravel/register and the store() using POST http://localhost/laravel/register

然后,索引()可以通过访问http://localhost/laravel/register并使用http://localhost/laravel/register来访问。

Chaneg the http://localhost/laravel/ with yours.

Chaneg: http://localhost/laravel/与您的。

And the same way the update($id) is used for update and destroy($id) is used for delete

和更新($id)用于更新和销毁($id)的方式相同,用于删除。

#2


1  

Route::controller('register', 'RegisterController');

路线:控制器(“注册”、“RegisterController”);

This will also work if you change it

如果你改变它,它也会起作用。

Route::controller('/', 'RegisterController');

路线:控制器(' / ',' RegisterController ');

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/10/06/df3312759b44eb5f63674a95750745bf.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告