<?php /** * Zend_Controller_Front 精简版 转载请注明 * @author wolf [Qq: 116311316] * @example $front=Custom_Controller_Front::getInstance(); * @version 1.0 * */ class Custom_Controller_Front { protected static $_instance = null; //Zend_Controller_Front 单例模式 protected $_dispatcher; //派遣器 protected $_router = null; //路由器 /** *获得Front实例 * @return Zend_Controller_Front */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } /** *获得一个派遣器 * @return Zend_Controller_Dispatcher */ public function getDispatcher() { if (! $this->_dispatcher instanceof Custom_Controller_Dispatcher) { $this->_dispatcher = new Custom_Controller_Dispatcher(); } return $this->_dispatcher; } /** * 设置控制器目录 必须的 * @param string|array $directory Path to Zend_Controller_Action controller * @param string $module Optional module name to use with string $directory * @return Zend_Controller_Front */ public function setControllerDirectory($directory, $module = null) { $this->getDispatcher()->setControllerDirectory($directory, $module); return $this; } /** * 获得一个路由器 官方copy的 * @return Custom_Controller_Router_Rewrite */ public function getRouter() { if (null == $this->_router) { $this->_router = new Custom_Controller_Router_Rewrite(); } return $this->_router; } /** * 这里自定义设置派遣器 默认继承了Custom_Controller_Dispatcher_Interface接口 * 这里我列举一种 其他的都一样 * @link http://www.cnblogs.com/terryglp/articles/1775778.html * @return Zend_Controller_Dispatcher */ public function setDispatcher(Custom_Controller_Dispatcher_Interface $dispatcher) { $this->_dispatcher = $dispatcher; return $this; } /** * 非常重要 三步完成任务 request router dispatch * Dispatch an HTTP request to a controller/action. * @return void */ public function dispatch() { $request = new Custom_Controller_Request(); //这里直接得到一个request; $router = $this->getRouter(); //交给路由进行解析 $router->route($request); $this->getDispatcher()->dispatch($request); } } // End ^ LF ^ UTF-8