background image

);

 

?>

 

没 什 么 特 别 的 就 是 一 个 数 组 ,   有 三 个 值 ,   暂 时 先 这 样 ,  

 

以 后 有 需 要 在 来 增 加

,

 

Controll.class.php

 

<?php

 

class

 

Controller

 

{

 

public

 

function

 

Run()

 

{

 

$this->Analysis();   // 开 始 解 析 URL

 

获 得 请 求 的 控 制 器 和 方 法

$control

 

=

 

$_GET['c'];

 

$action

 

=

 

$_GET['a'];

 

//

 

$controlFile   =   ROOT_PATH   .   '/Controllers/'   .   $control   .   '.class.php';  
if(!file_exists($controlFile))   // 如 果 文 件 不 存 在 提 示 错 误 ,  

 

否 则 引 入

{

 

exit('

'   .   $controlFile);

 

}

 

include($controlFile);

 

$class = ucwords($control); //将控制器名称中的每个单词首字母大写,来当作控制器

 

if(!class_exists($class))   // 判 断 类 是 否 存 在 ,  

 

如 果 不 存 在 提 示 错 误

{

 

exit('

'   .   $class);

 

}

 

$instance   =   new   $class();   //

 

if(!method_exists($instance, $action)) //判断实例$instance 中是否存在$action 方

,

 

 

{

 

exit('

'

 

.

 

$action);

 

}

 

$instance->$action();

 

}

 

/**

 

*

 

URL

 

*

 

*

 

@access

 

protected

 

*

 

@return

 

void

 

*/

 

protected

 

function

 

Analysis()

 

{

 

global $C; //包含全局配置数组, 这个数组是在 Config.ph

 

文件中定义的

//根据配置文件 Config.php 中的全局数组$c,根据$c[‘URL_MODE’]的值判断 url 的模