Problem s FilterRoute chyba params[‚language‘]
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- David Ďurika
- Člen | 328
Zdravim
mam nieco taketo:
bootstrap.php
<?php
$frontRouter[] = $filterRoute = new Core\Application\Routers\FilterRoute("[!<language ([a-z]{2})>]/<id [a-z-]+>", array(
'presenter' => 'Page',
'action' => 'show',
'language' => 'sk',
));
$filterRoute->addFilter('id', '\\Models\\PageModel::slugToId', '\\Models\\PageModel::idToSlug');
?>
PageModel.php
<?php
public static function idToSlug($id, \Nette\Application\Request $request)
{
$args = array('SELECT p.webalize
FROM pages AS p
JOIN [z_'.$request->params['language'].'] AS z ON p.title_dic_id=z.id
WHERE z.id=%i', $id);
$id = \dibi::query($args)->fetchSingle();
return $id;
}
public static function slugToId($slug, \Nette\Application\Request $request)
{
$args = array('SELECT p.id
FROM pages AS p
JOIN [z_'.$request->params['language'].'] AS z ON p.title_dic_id=z.id
WHERE z.webalize=%s', $slug);
$id = \dibi::query($args)->fetchSingle();
return $id;
}
?>
BasePresenter.php
<?php
/**
* @persistent
*/
public $language = 'sk';
?>
<?php
$this->link(':Front:Page:show', array('language' => 'sk', 'id' => 2));
//alebo
$this->link(':Front:Page:show', array('id' => 2));
?>
ale v PageModel::idToSlug mam $request->params[‚language‘] stale NULL preco ?
Editoval achtan (1. 9. 2011 16:54)
- David Ďurika
- Člen | 328
neviem preco, ale ked som BasePresenter.php zmenil na:
<?php
/**
* @persistent
*/
public $language = NULL;
?>
tak uz to ide spravne… :)