php mvc框架控制器核心代码
<?phpif(!defined("APPLICATION_MODULE_PARAM")):define("APPLICATION_MODULE_PARAM","m");endif;
if(!defined("APPLICATION_MODULE_BASIC_PATH")):define("APPLICATION_MODULE_BASIC_PATH","");endif;
if(!defined("APPLICATION_CONTROLLER_PARAM")):define("APPLICATION_CONTROLLER_PARAM","c");endif;
if(!defined("APPLICATION_ACTION_PARAM")):define("APPLICATION_ACTION_PARAM","a");endif;
if(!defined("NULL")):define("NULL",null);endif;
class application
{
private static $application=NULL;
private $module=NULL;
private $controller=NULL;
private $action=NULL;
private function __construct(){}
public static function getInstance()
{
if(!(self::$application instanceof self)):
self::$application=new self();
endif;
return self::$application;
}
public function run()
{
$this->module=$_GET;
$this->controller=$_GET;
$this->action=$_GET;
if(!is_dir(APPLICATION_MODULE_BASIC_PATH.$this->module)):
exit("module ".APPLICATION_MODULE_BASIC_PATH.$this->module." not exist");
endif;
if(!file_exists(APPLICATION_MODULE_BASIC_PATH.$this->module.'/'.$this->controller.'.php')):
exit("controller ".APPLICATION_MODULE_BASIC_PATH.$this->module.'/'.$this->controller.'.php'." not exist");
endif;
if(!class_exists($this->controller)):
include APPLICATION_MODULE_BASIC_PATH.$this->module.'/'.$this->controller.'.php';
endif;
$temp=new $this->controller;
if(!method_exists($temp,$this->action)):
exit("action $this->action not exist");
endif;
return call_user_method($this->action,$temp);
}
}
?>
<?php
require'lib/application.cls.php';
$app=application::getInstance();
$app->run();
?>
小孟 鹤峰
页:
[1]