製品カタログのルートを作成するのに助けが必要です。次のような URL が必要です。
/製品/エレクトロニクス/14
/製品/エレクトロニクス/コンピュータ
/製品/エレクトロニクス/コンピューター/ラップトップ/4
URL の最後の数字は、現在のリストのページ番号を示しています。
製品カタログのルートを作成するのに助けが必要です。次のような URL が必要です。
/製品/エレクトロニクス/14
/製品/エレクトロニクス/コンピュータ
/製品/エレクトロニクス/コンピューター/ラップトップ/4
URL の最後の数字は、現在のリストのページ番号を示しています。
独自のカスタム ルートを定義する必要があると思います (速度が速いため、そのためには正規表現を好みます)。
3 つのレベルのカテゴリがあると仮定します。さらに必要な場合は、ループを作成してルートを作成します。必要に応じてコントローラーとアクションを変更します。page param が必要であると仮定しました-そうでない場合は正規表現を変更します。
$router = Zend_Controller_Front::getInstance()->getRouter();
//main category route
$router->addRoute(
'category_level_0',
new Zend_Controller_Router_Route_Regex(
'/products/(\w+)/(\d+)',
array(
'controller' => 'product',
'action' => 'category',
'module' => 'default'
),
array(
1 => 'category_name',
2 => 'page_nr'
),
'/products/%s/%d'
)
);
//sub category route
$router->addRoute(
'category_level_1',
new Zend_Controller_Router_Route_Regex(
'/products/(\w+)/(\w+)/(\d+)',
array(
'controller' => 'product',
'action' => 'category',
'module' => 'default'
),
array(
1 => 'category_name',
2 => 'sub_category_name'
3 => 'page_nr'
),
'/products/%s/%s/%d'
)
);
//sub sub category route :)
$router->addRoute(
'category_level_2',
new Zend_Controller_Router_Route_Regex(
'/products/(\w+)/(\w+)/(\w+)/(\d+)',
array(
'controller' => 'product',
'action' => 'category',
'module' => 'default'
),
array(
1 => 'category_name',
2 => 'sub_category_name'
3 => 'sub_sub_category_name'
4 => 'page_nr'
),
'/products/%s/%s/%s/%d'
)
);
次のような複数のルートを追加する必要があります
$router->addRoute('level1cat', new Zend_Controller_Router_Route(
'products/:cat1/:page',
array(
'controller' => 'product',
'action' => 'index',
'page' => 1
),
array(
'cat1' => '\w+',
'page' => '\d+'
)
));
$router->addRoute('level2cat', new Zend_Controller_Router_Route(
'products/:cat1/:cat2/:page',
array(
'controller' => 'product',
'action' => 'index',
'page' => 1
),
array(
'cat1' => '\w+',
'cat2' => '\w+',
'page' => '\d+'
)
));
$router->addRoute('level3cat', new Zend_Controller_Router_Route(
'products/:cat1/:cat2/:cat3/:page',
array(
'controller' => 'product',
'action' => 'index',
'page' => 1
),
array(
'cat1' => '\w+',
'cat2' => '\w+',
'cat3' => '\w+',
'page' => '\d+'
)
));
ルートごとに異なるコントローラー アクションを使用することもできます。データを実際にどのように処理するかはユーザー次第です。
注、これは完全にテストされておらず、現時点での私の最善の推測です(現在.NETで作業しているため、モックアップすることさえできません)