没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Zend Framework教程之分发器教程之分发器Zend_Controller_Dispatcher
用法详解用法详解
主要介绍了Zend Framework教程之分发器Zend_Controller_Dispatcher用法,结合实例形式详细分析了分发器
Zend_Controller_Dispatcher的结构,功能,使用技巧与相关注意事项,需要的朋友可以参考下
本文实例讲述了Zend Framework教程之分发器Zend_Controller_Dispatcher用法。分享给大家供大家参考,具体如下:
分发器的具体实现分发器的具体实现
Zend Framework的分发器Zend_Controller_Dispatcher设计主要有,如下类和接口组成:
├── Dispatcher
│ ├── Abstract.php
│ ├── Exception.php
│ ├── Interface.php
│ └── Standard.php
Zend_Controller_Dispatcher_Interface
定义了分发器提供的基本和标准功能。
interface Zend_Controller_Dispatcher_Interface
{
public function formatControllerName($unformatted);
public function formatModuleName($unformatted);
public function formatActionName($unformatted);
public function isDispatchable(Zend_Controller_Request_Abstract $request);
public function setParam($name, $value);
public function setParams(array $params);
public function getParam($name);
public function getParams();
public function clearParams($name = null);
public function setResponse(Zend_Controller_Response_Abstract $response = null);
public function getResponse();
public function addControllerDirectory($path, $args = null);
public function setControllerDirectory($path);
public function getControllerDirectory();
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response);
public function isValidModule($module);
public function getDefaultModule();
public function getDefaultControllerName();
public function getDefaultAction();
}
Zend_Controller_Dispatcher_Abstract
实现了Zend_Controller_Dispatcher_Interface接口,提供了分发器提供的基本和标准功能的抽象父类。
<?php
/** Zend_Controller_Dispatcher_Interface */
require_once 'Zend/Controller/Dispatcher/Interface.php';
abstract class Zend_Controller_Dispatcher_Abstract implements Zend_Controller_Dispatcher_Interface
{
protected $_defaultAction = 'index';
protected $_defaultController = 'index';
protected $_defaultModule = 'default';
protected $_frontController;
protected $_invokeParams = array();
protected $_pathDelimiter = '_';
protected $_response = null;
protected $_wordDelimiter = array('-', '.');
public function __construct(array $params = array())
{
$this->setParams($params);
}
public function formatControllerName($unformatted)
{
return ucfirst($this->_formatName($unformatted)) . 'Controller';
}
public function formatActionName($unformatted)
{
$formatted = $this->_formatName($unformatted, true);
return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1) . 'Action';
}
public function _verifyDelimiter($spec)
{
if (is_string($spec)) {
return (array) $spec;
} elseif (is_array($spec)) {
$allStrings = true;
foreach ($spec as $delim) {
if (!is_string($delim)) {
$allStrings = false;
break;
}
}
if (!$allStrings) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Word delimiter array must contain only strings');
}
return $spec;
}
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid word delimiter');
}
public function getWordDelimiter()
{
return $this->_wordDelimiter;
}
public function setWordDelimiter($spec)
{
$spec = $this->_verifyDelimiter($spec);
$this->_wordDelimiter = $spec;
return $this;
}
public function getPathDelimiter()
{
return $this->_pathDelimiter;
}
public function setPathDelimiter($spec)
{
if (!is_string($spec)) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid path delimiter');
}
$this->_pathDelimiter = $spec;
return $this;
}
protected function _formatName($unformatted, $isAction = false)
{
// preserve directories
if (!$isAction) {
$segments = explode($this->getPathDelimiter(), $unformatted);
} else {
$segments = (array) $unformatted;
}
foreach ($segments as $key => $segment) {
$segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment));
$segment = preg_replace('/[^a-z0-9 ]/', '', $segment);
$segments[$key] = str_replace(' ', '', ucwords($segment));
}
return implode('_', $segments);
}
public function getFrontController()
{
if (null === $this->_frontController) {
require_once 'Zend/Controller/Front.php';
$this->_frontController = Zend_Controller_Front::getInstance();
}
return $this->_frontController;
}
public function setFrontController(Zend_Controller_Front $controller)
{
$this->_frontController = $controller;
return $this;
}
public function setParam($name, $value)
{
$name = (string) $name;
$this->_invokeParams[$name] = $value;
return $this;
}
public function setParams(array $params)
{
剩余12页未读,继续阅读
资源评论
weixin_38665804
- 粉丝: 11
- 资源: 942
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于SSM框架的大学消息通知系统服务端.zip
- (源码)基于Java Servlet的学生信息管理系统.zip
- (源码)基于Qt和AVR的FestosMechatronics系统终端.zip
- (源码)基于Java的DVD管理系统.zip
- (源码)基于Java RMI的共享白板系统.zip
- (源码)基于Spring Boot和WebSocket的毕业设计选题系统.zip
- (源码)基于C++的机器人与船舶管理系统.zip
- (源码)基于WPF和Entity Framework Core的智能货架管理系统.zip
- SAP Note 532932 FAQ Valuation logic with active material ledger
- (源码)基于Spring Boot和Redis的秒杀系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功