• 本帖最后由 aite.me 于 2013-8-25 18:24 编辑 *
  • ControllerName = (isset($_GET[$Config['UrlControllerName']]) && !empty($_GET[$Config['UrlControllerName']])) ? trim($_GET[$Config['UrlControllerName']]) : 'index';
  • $this -> ActionName = (isset($_GET[$Config['UrlActionName']]) && !empty($_GET[$Config['UrlActionName']])) ? trim($_GET[$Config['UrlActionName']]) : 'IndexAction';
  • $this -> ControllerFile = _CONTROLLER. $this -> ControllerName . '.php';
  • }
  • public function ControllerStart() {
  • (is_file($this -> ControllerFile) && require $this -> ControllerFile) || (is_file(_CONTROLLER . 'index.php') && require _CONTROLLER . 'index.php') || self::notice('Controller File No Found !');
  • class_exists($this -> ControllerName) || ($this -> ControllerName = 'index' && class_exists($this -> ControllerName)) || self::notice('Controller Class No Found !');
  • $methods = get_class_methods($this -> ControllerName);
  • in_array($this -> ActionName, $methods, true) || ($this -> ActionName = 'IndexAction' && in_array($this -> ActionName, $methods, true)) || self::notice('Controller Method No Found !');
  • $KernelController = new $this -> ControllerName($_GET);
  • $KernelController -> {$this -> ActionName}();
  • }
  • static public function notice($notice) {
  • exit($notice);
  • }
  • static public function filter(&$array, $function) {
  • if(!is_array($array)) return $array = $function($array);
  • foreach($array as $key => $value) (is_array($value) && $array[$key] = Kernel::filter($value, $function)) || $array[$key] = $function($value);
  • return $array;
  • }
  • }
  • class KernelView {
  • public $ViewValue;
  • public function __construct() {
  • }
  • public function _view($file = null) {
  • $file = _VIEW . $file . '.php';
  • extract($this -> ViewValue);
  • if(is_file($file)) return require $file;
  • Kernel::notice('View File No Found !');
  • }
  • }
  • class KernelModel {
  • }
  • class KernelController {
  • public $KernelView;
  • public $KernelClass;
  • public $KernelModel;
  • public function __construct() {
  • global $Config;
  • $this -> KernelView = new KernelView();
  • }
  • public function __set($name, $value = null) {
  • $this -> KernelView -> ViewValue[$name] = $value;
  • }
  • public function _view($file = null) {
  • global $Config;
  • $KernelSelfPropertyKey = array_keys(get_class_vars('KernelController'));
  • $ControllerPropertyParam = get_object_vars($this);
  • foreach($ControllerPropertyParam as $key=>$val)
  • {
  • if(!in_array($key, $KernelSelfPropertyKey)) $this -> KernelView -> ViewValue[$key] = $val;
  • }
  • $this -> KernelView -> _view($file);
  • }
  • public function _model($file, $ClassName = null) {
  • $ClassName = $ClassName == null ? $file : $ClassName;
  • $file = _MODEL . $file . '.php';
  • if(is_file($file)) {
  • require $file;
  • if(!class_exists($ClassName)) Kernel::notice('Class No Found !');
  • if(!isset($this -> KernelModel[$ClassName])) $this -> KernelModel[$ClassName] = new $ClassName();
  • return $this -> KernelModel[$ClassName];
  • }
  • }
  • public function _class($file, $ClassName = null) {
  • $ClassName = $ClassName == null ? $file : $ClassName;
  • $file = _CLASS . $file . '.php';
  • if(is_file($file)) {
  • require $file;
  • if(!class_exists($ClassName)) Kernel::notice('Class No Found !');
  • if(!isset($this -> KernelClass[$ClassName])) $this -> KernelClass[$ClassName] = new $ClassName();
  • return $this -> KernelClass[$ClassName];
  • }
  • }
  • }
  • ?>复制代码学着用mvc模式做程序了,看了下amp,我自己试着折腾,require进来的文件中模型和视图的类名不能一样,否则控制器出_view方**出错,另外想说一下,数据库连接放在子模型中还是主模型中?示范代码没有做文件系统\0之类的安全处理。