Вот отрывок из router.class.php .
И выдает он ошибки
Notice: Undefined offset: 2 in classes/router.php on line 5
Notice: Undefined offset: 3 in classes/router.php on line 9
Notice: Undefined offset: 1 in classes/router.php on line 12
Notice: Undefined offset: 3 in classes/router.php on line 14
Notice: Undefined offset: 4 in classes/router.php on line 15
Notice: Undefined offset: 5 in classes/router.php on line 16
public static function executeAction() {
$module = isset(self::$params[0]) ? self::$params[0]: 'index';
$action = isset(self::$params[1]) ? self::$params[1]: 'default';
$params = self::$params[2];
$_GET['app'] = $action;
$_GET['add'] = $params;
$_GET['param'] = $params;
$_GET['param_2'] = self::$params[3];
$_GET['page_name'] = $module;
$_GET['prm_0'] = isset(self::$params[0]) ? self::$params[0]: 'index';
$_GET['prm_1'] = self::$params[1];
$_GET['prm_2'] = isset(self::$params[2]) ? self::$params[2]: 'default';
$_GET['prm_3'] = self::$params[3];
$_GET['prm_4'] = self::$params[4];
$_GET['prm_5'] = self::$params[5];
if (file_exists('core/modules/' . $_GET['prm_0'] . '/main.php')) {
require_once 'core/modules/' . $_GET['prm_0'] . '/main.php';
} else {
$tpl->content = $eng->msg('2', 'Ошибка, страница не найдена!', '2');
}
}
Вот полный класс
class router {
public static $routes = array();
private static $params = array();
public static $requestedUrl = '';
public static function addRoute($route, $destination=null) {
if ($destination != null && !is_array($route)) {
$route = array($route => $destination);
}
self::$routes = array_merge(self::$routes, $route);
}
public static function splitUrl($url) {
return preg_split('/\//', $url, -1, PREG_SPLIT_NO_EMPTY);
}
public static function getCurrentUrl() {
return (self::$requestedUrl?:'/');
}
public static function dispatch($requestedUrl = null) {
if ($requestedUrl == null) {
//$uri = reset(explode('?', $_SERVER["REQUEST_URI"]));
$arr = explode('?', $_SERVER["REQUEST_URI"]);
$uri = reset($arr);
$requestedUrl = urldecode(rtrim($uri, '/'));
}
self::$requestedUrl = $requestedUrl;
if (isset(self::$routes[$requestedUrl])) {
self::$params = self::splitUrl(self::$routes[$requestedUrl]);
return self::executeAction();
}
foreach (self::$routes as $route => $uri) {
if (strpos($route, ':') !== false) {
$route = str_replace(':any', '(.+)', str_replace(':num', '([0-9]+)', $route));
}
if (preg_match('#^'.$route.'$#', $requestedUrl)) {
if (strpos($uri, '$') !== false && strpos($route, '(') !== false) {
$uri = preg_replace('#^'.$route.'$#', $uri, $requestedUrl);
}
self::$params = self::splitUrl($uri);
break;
}
}
return self::executeAction();
}
public static function executeAction() {
$module = isset(self::$params[0]) ? self::$params[0]: 'index';
$action = isset(self::$params[1]) ? self::$params[1]: 'default';
$params = self::$params[2];
$_GET['app'] = $action;
$_GET['add'] = $params;
$_GET['param'] = $params;
$_GET['param_2'] = self::$params[3];
$_GET['page_name'] = $module;
$_GET['prm_0'] = isset(self::$params[0]) ? self::$params[0]: 'index';
$_GET['prm_1'] = self::$params[1];
$_GET['prm_2'] = isset(self::$params[2]) ? self::$params[2]: 'default';
$_GET['prm_3'] = self::$params[3];
$_GET['prm_4'] = self::$params[4];
$_GET['prm_5'] = self::$params[5];
if($_GET['prm_0'] == 'admin') {
if (file_exists('app/' . $_GET['prm_1'] . '/main.php')) {
require_once 'app/' . $_GET['prm_1'] . '/main.php';
} else {
$tpl->content = $eng->msg('2', 'Ошибка, страница не найдена!', '2');
}
} else {
if (file_exists('core/modules/' . $_GET['prm_0'] . '/main.php')) {
require_once 'core/modules/' . $_GET['prm_0'] . '/main.php';
} else {
$tpl->content = $eng->msg('2', 'Ошибка, страница не найдена!', '2');
}
}
}
}