Route::set('search', 'search')
->defaults(array(
'directory' => '',
'controller' => 'search',
'action' => 'index',
));
$url = Route::url('search');
class Controller_Search extends Controller_... {
public function action_index() {}
}
Route::set('contacts', 'contacts')
->defaults(array(
'directory' => '',
'controller' => 'page',
'action' => 'contacts',
));
Route::set('page', 'page/<id>', array('id' => '[-\w\/]+'))
->defaults(array(
'directory' => '',
'controller' => 'page',
'action' => 'dynamic',
'id' => '',
));
$url = Route::url('page', array('id' => 'about'));
$url = Route::url('contacts');
class Controller_Page extends Controller_... {
public function action_contacts() {}
public function action_dynamic() {}
}
Route::set('news', 'news/<id>', array('id' => '[-\w\/]+'))
->defaults(array(
'directory' => '',
'controller' => 'news',
'action' => 'index',
'id' => '',
));
$url = Route::url('news', array('id' => 'first-post'));
class Controller_News extends Controller_... {
public function action_index() {}
}
Route::set('widget', 'widget/<controller>(/<param>)', array('controller' => '[\w]+', 'param' => '[-\w\.\/]+'))
->defaults(array(
'directory' => 'widget',
'controller' => '',
'action' => 'index',
'param' => '',
));
$url = Route::url('widget', array('controller' => 'menu'));
class Controller_Widget_... extends Controller_... {
public function action_index() {}
}
Route::set('auth', '<action>', array('action' => '(login|logout|register)'))
->defaults(array(
'directory' => '',
'controller' => 'auth',
'action' => 'login',
));
$url = Route::url('auth');
$url = Route::url('auth', array('action' => 'logout'));
class Controller_Auth extends Controller_... {
public function action_login() {}
public function action_logout() {}
public function action_register() {}
}
Route::set('admin', 'admin(/<controller>(/<action>(/<id>)))', array('controller' => '[\w]+', 'action' => '[\w]+', 'id' => '[-\w]+'))
->defaults(array(
'directory' => 'admin',
'controller' => 'main',
'action' => 'index',
'id' => '',
));
$url = Route::url('admin');
$url = Route::url('admin', array('controller' => 'admin', 'action' => 'add'));
class Controller_Admin_Main extends Controller_... {
public function action_index() {}
}
Route::set('default', '(<controller>(/<action>(/<id>)))', array('controller' => '[\w]+', 'action' => '[\w]+', 'id' => '[-\w]+'))
->defaults(array(
'directory' => '',
'controller' => 'main',
'action' => 'index',
'id' => '',
));
$url = Route::url('default');
$url = Route::url('default', array('controller' => 'news'));
class Controller_Main extends Controller_... {
public function action_index() {}
}
1. задаем regexp выражения и значения по умолчанию для всех параметров роутов
2. роуты объявляются в порядке от наиболее простых к сложным
3. ссылки генерим с помощью Route::url()