вот написал роутер под свои нужды
так добаляется маршрут
$router->addRoute( 'cars',
':module/:marka/:model/:submodel/:user/:controller/:action',
array('controller'=>'index',
'action'=>'index')
);
первый параметр название маршрута
шаблон маршрута
третий параметры по умолчанию
метод добавления маршрута
public function addRoute($routename = 'index', $route = ':module/:controller/:action', $defaults = array('module'=>'index','controller'=>'index','action'=>'index'))
{
foreach (explode($this->Delimiter, $route) as $pos => $part) {
$routes[] = str_replace( ':' , '' , $part );
}
$this->routes[$routename]['route'] = $routes;
$this->routes[$routename]['routestr'] = $route;
$this->routes[$routename]['defaults'] = $defaults;
}
парсинг запроса и разбивка на параметры
public function Dispatcher($request)
{
$parts = trim($request , "/\\");
$parts = explode("/", $parts);
$first = strtolower($parts['0']);
if(array_key_exists($first, $this->routes))
{
foreach($parts as $pos => $part)
{
$var = $this->routes[$first]['route'][$pos];
$this->params[$var] = $part;
}
if(!array_key_exists('module', $this->params) && array_search('module', $this->routes[$first]['route'])) $this->params['module'] = $first;
if(!array_key_exists('controller', $this->params)) $this->params['controller'] = $this->routes[$first]['defaults']['controller'];
if(!array_key_exists('action', $this->params)) $this->params['action'] = $this->routes[$first]['defaults']['action'];
} else {
$this->params = array_merge($this->params, $this->routes['index']['defaults']);
}
}
}
Спустя 265 сек.
тупой форум даже редактировать нельзя сообщение,
на выходе в переменной $this->params будут содержаться все нужные параметры
запрос
/cars/bmw/m3_coupe/m3_coupe_e92/antonflai/journal/288230376152133235/
результат
Array ( [module] => cars [marka] => bmw [model] => m3_coupe [submodel] => m3_coupe_e92 [user] => antonflai [controller] => journal [action] => 288230376152133235 )