如何在MVC类页面中基于漂亮的URL加载类?
http://example.com/blog/cosplay/cosplayer-expo-today
class Autoload{
var $url;
var $controller;
function __construct()
{
$this->url = $_GET['url'];
//HNEM ÜRES AZ URL
if($this->url!='' && !empty($this->url))
{
require 'application/config/routes.php';
//URL VIZSGÁLATA
$this->rewrite_url($this->url);
//URL SZÉTBONTÁSA
$this->url = explode('/', $this->url);
$file = 'application/controllers/'.$this->url[0].'.php';
//LÉTEZIK A CONTROLLER?
if(file_exists($file))
{
require $file;
$this->controller = new $this->url[0];
//KÉRELEM ALATT VAN AZ ALOLDAL?
if(isset($this->url[1]))
{
//LÉTEZIK A METÓDUS? ENGEDÉLYEZVE VAN?
if(method_exists($this->controller, $this->url[1]) && in_array($this->url[1], $route[$this->url[0]]))
{
if(isset($this->url[2]))
{
$this->controller->{$this->url[1]}($this->url[2]);
}
else
{
$this->controller->{$this->url[1]}();
}
}
else
{
header('location:'.SITE.$this->url[0]);
die();
}
}
}九州编程