více stylů routeru např. pro id

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Oggy
Člen | 306
+
0
-

Mohu mít více stylů routeru např. pro id?

je situace, kdy bych chtěl filtorvat id vícekrát..nebo spíše pro každou action např.

něco jako toto:

pokud je action nebo presenter např. article

<?php

Route::addStyle('id');
Route::setStyleProperty('id', Route::FILTER_IN, callback('ArticleModel::getIdByUrl'));
Route::setStyleProperty('id', Route::FILTER_OUT, callback('ArticleModel::getUrlById'));

?>

pokud je action nebo presenter např. product

<?php

Route::addStyle('id');
Route::setStyleProperty('id', Route::FILTER_IN, callback('ProductModel::getIdByUrl'));
Route::setStyleProperty('id', Route::FILTER_OUT, callback('ProductModel::getUrlById'));

?>

Jak by toto šlo provést?

Jan Tvrdík
Nette guru | 2595
+
0
-
Route::addStyle('#articleId');
Route::setStyleProperty('#articleId', Route::FILTER_IN, callback('ArticleModel::getIdByUrl'));
Route::setStyleProperty('#articleId', Route::FILTER_OUT, callback('ArticleModel::getUrlById'));

Route::addStyle('#productId');
Route::setStyleProperty('#productId', Route::FILTER_IN, callback('ProductModel::getIdByUrl'));
Route::setStyleProperty('#productId', Route::FILTER_OUT, callback('ProductModel::getUrlById'));

new Route('<presenter>/<action>/<id #articleId>');
Oggy
Člen | 306
+
0
-

děkuju ..

možná by stálo za to to přidat do dokumentace

Editoval Oggy (18. 3. 2010 14:44)

Mesiah
Člen | 240
+
0
-

Co přesně prosím Vás dělá # ?
Díky němu se budou procházet všechny styly routy, začínajícím stejným znakem? Lze použít i libovolný jiný znak?

David Grudl
Nette Core | 8147
+
0
-

Ve verzi 1.0 by mělo jít

new Route('<presenter>/<action>/<id>', array(
	'id' => array(
		Route::VALUE => 0, // default value
		Route::FILTER_IN => callback('ArticleModel::getIdByUrl'),
		Route::FILTER_OUT => callback('ArticleModel::getUrlById'),
	),
));
basovnik
Člen | 23
+
0
-

Ahoj, přečetl jsem si už spoustu návodů, ale ty routery mi pořád nefungují. Vždy mi to hodí chybu:
Fatal error: Exception thrown without a stack frame in Unknown on line 0
a url se nijak nezmeni…

<?php
function getIdByUrl($url) {
     return intval($url);
}

function getUrlById($id) {
        return $id."-klient";
}

Route::addStyle('#seo');
Route::setStyleProperty('#seo', Route::FILTER_IN, callback('getIdByUrl'));
Route::setStyleProperty('#seo', Route::FILTER_OUT, callback('getUrlById'));



// mod_rewrite detection
if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules())) {
	$router[] = new Route('index.php', 'Front:Default:default', Route::ONE_WAY);

	$router[] = $adminRouter = new MultiRouter('Admin');
	$adminRouter[] = new Route('admin/<presenter>/<action>[/<id>]', 'Default:default');
	$adminRouter[] = new Route('admin/clients/detail/<id #seo>');


	$router[] = $frontRouter = new MultiRouter('Front');
	$frontRouter[] = new Route('<presenter>/<action>[/<id>]', 'Default:default');

} else {
	$router[] = new SimpleRouter('Front:Default:default');
}
?>

Pomůžete mi někdo prosím?

Editoval basovnik (17. 2. 2011 22:16)