【发布时间】:2015-03-14 14:18:37
【问题描述】:
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)
【问题讨论】: