我試圖理解Laravel 4中的路由。我讀了一篇很好的post here on StackOverflow和一篇關於手動指定路由的文章beware the route to evil的鏈接。我喜歡手動指定我的路線並使routes.php充當文檔的想法。但似乎我需要謹慎對待我的路線的順序,如果我要指定我自己的而不是使用Route::resource()
如果我有new
或create
路線在show
之前,那麼我不會路由到該節目,因爲URI中的變量?路線的定義順序很重要?在Laravel 4中指定安靜路線的必需順序?
// This will not work if I try and browse to dogs/new
Route::get('dogs', array('as' => 'dogs', 'uses' => '[email protected]'));
Route::get('dogs/{dogs}', array('as' => 'dog', 'uses' => '[email protected]'));
Route::get('dogs/new', array('as' => 'new_dog', 'uses' => '[email protected]'));
看來我需要確保的是,dogs/new
而來的dogs/{dogs}
新前正確地返回。我不清楚什麼{dogs}
做什麼或不同於(:any)
或{any}
我在示例和僞代碼中看到了幾種不同的用法。我看到/new
與{...}
相同,當時路由是在Laravel 4中的通配符之前更具體的{}。 (...)是舊的方式嗎?
順便說一句,我從一些時,我與像Route::resource('photos', 'PhotosController');
方法的資源路線行駛php artisan routes
我見過的例子注意到一個不同的命名約定並命名爲後路線索引來創建新的資源命名爲photos.store和@store。鏈接到表單以創建新資源的方法和命名路由爲photos.create和@create。 Laravel 4是其他框架中的東西還是約定?