Routa s viacerimi parametrami
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- duskohu
- Člen | 778
Caute snazim sa rozbehat router pre akciu ktora ma viacej parametrov. problem je v tom ze sa neposielaju vsetky naraz, ale ale mozu sa poslat ich kombinacie. Problem je v tom ze mi tu routu vezme ale v parametroch mam:
category 10
district NULL
a do url mi ani district slug neda. Neviete mi poradit co mam zle?
function actionDefault($category = NULL, $transaction = NULL, $city = NULL, $district = NULL){
}
link:
$values=array(
'category'=>10,
'transaction'=>'',
'district'=>20,
'city'=>'',
);
$this->presenter->redirect(':Default:Front:Estate:default', $values);
a router:
$defaultRouter[] = new Route('test[/<category .*>][/<district .*>]', array(
'module' => 'Front',
'presenter' => 'Estate',
'action' => 'default',
'category' => array(
Route::FILTER_IN => function ($category) use ($that) {
if (is_numeric($category)) {
return $category;
}
$categoryEntity = $that->categoryRepository->findOneBy(
array(
'link' => $category,
)
);
if ($categoryEntity) {
return $categoryEntity->id;
}
return NULL;
},
Route::FILTER_OUT => function ($category) use ($that) {
if (!is_numeric($category)) {
return $category;
}
$categoryEntity = $that->categoryRepository->findOneBy(
array(
'id' => $category,
)
);
if ($categoryEntity) {
return $categoryEntity->link;
}
}
),
'district' => array(
Route::FILTER_IN => function ($district) use ($that) {
bd($district);
if (is_numeric($district)) {
return $district;
}
$districtEntity = $that->districtRepository->findOneBy(
array(
'link' => $district,
)
);
if ($districtEntity) {
return $districtEntity->id;
}
return NULL;
},
Route::FILTER_OUT => function ($district) use ($that) {
if (!is_numeric($district)) {
return $district;
}
$districtEntity = $that->districtRepository->findOneBy(
array(
'id' => $district,
)
);
if ($districtEntity) {
return $districtEntity->link;
}
}
),
));