1

Laravel でいくつかのルートの問題があります。いい方法を取っていないからだと思いますが…

これが私のコードです:

Route::group(array('prefix' => 'products'), function()
{
    Route::get('', array('uses'=>'products@index'));
    //show all the products 

    Route::get('{Categorie}',array('uses'=>'products@categorie'))->where('Categorie','^[A-Z][a-z0-9_-]{3,19}$');
    //show the products of this categorie   

    Route::get('{shopname}',array('uses'=>'products@shopname'))->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'=>'product@getProduct'));
    //the Product controller is now SINGULAR
    //show this product in particular
});

したがって、最初のグループで機能しています... mysite.fr/products => ok mysite.fr/MyCategory => ok mysite.fr/mashopname => ok

しかし、次のような2番目のパラメーターを追加すると:

mysite.fr/products/myshopname/myfirstproduct

特定のメッセージなしでエラーが発生しました...

助けてくれてありがとう!

4

1 に答える 1

1

ここでの問題は、これらがすべて同じルートであることです。Laravel は、カテゴリ、ショップ名、またはその他としてカウントされるものを知りません。たとえば、 にアクセスすると/products/test、Laravel は test がカテゴリなのか、ショップ名なのか、製品名なのかわかりません。

代わりにこれを試してください...

Route::group(array('prefix' => 'products'), function()
{
    Route::get('/', array('uses'=>'products@index'));
    //show all the products 

    Route::get('categorie/{Categorie}',array('uses'=>'products@categorie'))->where('Categorie','^[A-Z][a-z0-9_-]{3,19}$');
    //show the products of this categorie   

    Route::get('shopname/{shopname}',array('uses'=>'products@shopname'))->where('shopname','^[a- z][a-z0-9_-]{3,19}$');
    //show the product of this shopname

    Route::get('product/{productName}', array('uses'=>'product@getProduct'));
    //the Product controller is now SINGULAR
});

このようにして、 に行くとproducts/categorie/test、Laravel は私が を探していることを認識し、categorie適切にルーティングすることができます。

アップデート:

Hightechがカテゴリでが製品の場合product_1、次のようなルートを使用できます...

    Route::get('category/{categorie}/product/{product}',array('uses'=>'products@categorie'))->where('categorie','^[A-Z][a-z0-9_-]{3,19}$')->where('product','^[A-Z][a-z0-9_-]{3,19}$');
    //show the products of this categorie   

そして、URLは.com/products/category/Hightech/product/product_1. または、/product取り出して/category取り出して、そこに行くこともできます.com/products/Hightech/product_1

于 2013-10-28T12:20:38.133 に答える