postupne prochazeni nekolika routeru
- vosy
- Člen | 532
ahoj, v routeru mam
$router[] = $frontRouter = new RouteList('Front:Produkty');
$frontRouter[] = new Route('<presenter>/<action>/<id>',
array(
'presenter'=>NULL,
'action'=>'default',
'id'=>NULL
));
$router[] = $frontRouter = new RouteList('Front:Smlouva');
$frontRouter[] = new Route('<presenter>/<action>/<id>',
array(
'presenter'=>NULL,
'action'=>'default',
'id'=>NULL
));
$router[] = $frontRouter = new RouteList('Front');
$frontRouter[] = new Route('<presenter>/<action>/<id>',
array(
'presenter'=>'Homepage',
'action'=>'default',
'id'=>NULL
));
pak kdyz je treba url
tak aby se nejdrive zkontrolovaly presentery v ProduktyModule, SmlouvaModule a pak FrontModule
ted mi to hnedle vyhodit chybu ze nebyl nalezeny prezenter v ProduktyModule
- David Matějka
- Moderator | 6445
Ona vyhovi kazda routa – routovani nekontroluje, jestli existuje onen presenter. Pouze overuje, jestli HTTP pozadavek odpovida te route. Mohl by sis rucne overovat existenci presenteru ve FILTER_IN pomoci PresenterFactory, priblizne takhle:
$presenterFactory = ...; //v tom je Nette\Application\PresenterFactory
$frontRouter[] = new Route('<presenter>/<action>/<id>',
array(
'presenter'=>array(
Route::FILTER_IN = function($presenter) use($presenterFactory){
//v presenteru asi nebude uveden modul z RouteList, musis doplnit
$class = $presenterFactory->formatPresenterClass($presenter);
if(!class_exists($class)) {
return NULL;
}
return $presenter; //ale pozor, tady vracej bez modulu, pouze ten vstup..
}
),
'action'=>'default',
'id'=>NULL
));
- David Matějka
- Moderator | 6445
@akadlec: jelikoz ma action uvedenou defaultni hodnotu default, tak
ten parametr neni povinny, je to trochu matouci..
a hlavne by to ukazalo chybu, ze neodpovida zadna routa a ne, ze nebyl nalezen
presenter
- David Matějka
- Moderator | 6445
Pravda, tim se prepise defaultni filtr v route pro presenter :\
Zkus pouzit ten super filter NULL
, neco jako
$frontRouter[] = new Route('<presenter>/<action>/<id>', array(
NULL=>array(
Route::FILTER_IN => function($parameters) use($presenterFactory){
$presenter = $parameters['presenter'];
//....
if(!class_exists(...)) {
return NULL;
}
return $parameters;
}
),
));
Editoval matej21 (27. 5. 2014 13:37)