Loading...
PHP/MySQL | Роутинг
Вот делал для сайта роутинг,может кому надо))Решил сделать для себя автоматизированные...
plaintext

<?php

/**
* @package StrongCMS by MTV
*/

namespace system;

class Route
{
	protected static function routes()
	{
		return [
			'/' => '\application\controllers\Welcome@index',
			
			'/signup' => '\application\controllers\Signup@index',
			'/signup/confirm' => '\application\controllers\Signup@confirm'
		];
	}
	
	protected static function getUrl()
	{
		$string = strip_tags(stripslashes($_SERVER['REQUEST_URI']));
		return filter_var(trim($string), FILTER_SANITIZE_URL);
	}
	public static function start()
	{
		$found = FALSE;
		
		foreach(self::routes() as $regex => $value) 
		{
			if(preg_match('/^' . str_replace('/', '\/', $regex) . '\/?$/i', self::getUrl(), $matches)) {
				$found = TRUE;
				$routes = explode('@', $value);
				if(class_exists($routes[0])) {
					$class = new $routes[0]();
					if(method_exists($class, $routes[1])) {
						array_shift($matches);
						return call_user_func_array(array($class, $routes[1]), $matches);
					}
				}
			}
		}
		
		if($found == FALSE) {
			exit('Page does not exist.');
		}
	}
}
?>
порнуха, малый)))
178396284 (11.02.2016 в 01:05)
порнуха, малый)))
Почему порнуха?
Онлайн: 1
Время:
Gen. 0.0905
(c) Bym.Guru 2010-2026