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 的 模 式 , 从 而 知 道 如 何 获 取

if($C['URL_MODE'] == 1) //如果 URL 模式为 1 那么就在 GET 中获取控制器,
 也就是说 url 地址是这种的

http://localhost/index.php?c=控制器&a=