Laravel中的路由顺序很重要

时间:2015-01-16 01:52:17

标签: php laravel routes

路线的顺序在Laravel中是否重要?

我创建了以下路线:

Route::get('authors/new', array('as'=>'new_author', 'uses'=>'AuthorsController@getNew'));
Route::get('authors/{id}', array('as'=>'author', 'uses'=>'AuthorsController@getView'));

在作者控制器中,我有以下内容:

public function getView($id)
{
    return View::make('authors.view')
        ->with('title', 'Author View Page')
        ->with('author', Author::find($id));
}

public function getNew()
{
    return View::make('authors.new')
        ->with('title', 'Add New Author');
}

当我进入localhost/authors/new页面时,它运行正常。

但是,如果我改变这样的路线顺序:

Route::get('authors/{id}', array('as'=>'author', 'uses'=>'AuthorsController@getView'));
Route::get('authors/new', array('as'=>'new_author', 'uses'=>'AuthorsController@getNew'));

它不再起作用,它说:

Trying to get property of non-object (View: C:\xampp\htdocs\laravel\app\views\authors\view.blade.php)

0 个答案:

没有答案