MVC
by 蘇德宙, 2011-01-24 13:28, 人氣(1767)
存全域變數
Class Registry Implements ArrayAccess
{
private $vars = array();
private $vars = array();
function __construct() {}
function set($key, $var) { ... }
function get($key) { ... }
function remove($var) { ... }
function offsetExists($offset) { ... }
function offsetGet($offset) { ... }
function offsetSet($offset, $value) { .. }
function offsetUnset($offset) { ... }
}
1. 單一入口 index.php (用 .htaccess rewrite 確保)
2. 初始動作 includes/startup.php (constant / global variables, common tools)
3. 委派控制器 classes/router.php
delegate()
{
getController(&$file, &$controller, &$action, &$args)
include($file);
$class = 'Controller_' . $controller;
$controller = new $class($this->registry);
$controller = new $class($this->registry);
$controller->$action();
}
getController(&$file, &$controller, &$action, &$args)
{
?route=members/view => array('members', 'view')
}
4. 控制器 controllers/members.php, ...
Class Controller_Members Extends Controller_Base
{
function index() { ... } // default action
function view() { ... } // others, ex members/view
}
function view() { ... } // others, ex members/view
}
5.