我在Laravel遇到了一些路线问题。我想这是因为我不走的好方法,但...Laravel 4 - >具有多个变量的同一控制器上的路线
这里是我的代码:
Route::group(array('prefix' => 'products'), function()
{
Route::get('', array('uses'=>'[email protected]'));
//show all the products
Route::get('{Categorie}',array('uses'=>'[email protected]'))->where('Categorie','^[A-Z][a-z0-9_-]{3,19}$');
//show the products of this categorie
Route::get('{shopname}',array('uses'=>'[email protected]'))->where('shopname','^[a- z][a-z0-9_-]{3,19}$');
//show the product of this shopname
});
Route::group(array('prefix' => '/products/{:any}'), function()
{
//no index because productName is not optionnal
Route::get('{productName}', array('uses'=>'[email protected]'));
//the Product controller is now SINGULAR
//show this product in particular
});
所以它的工作为第一组... mysite.fr/products =>确定 mysite.fr/MyCategorie => OK mysite.fr/mashopname => OK
但是当我添加第二paramater等:
mysite.fr/products/myshopname/myfirstproduct
我得到一个错误与特定的消息...
非常感谢您的帮助!
我想到了这一点,但我的想法是保持网址中的商店名称/种类。你试试这个 - >“Route :: get('/ {:any}/{productName}',array(''),然后你去.com/products/Hightech/product_1。使用 '=>' 产品@ getProduct'));”但仍然是一个错误... – pierreaurelemartin
我刚刚更新了答案,所以你可以使用这样的URL。 – user1669496