Zend Framework动作助手Url用法详解
网络编程 2021-07-05 09:10www.168986.cn编程入门
这篇文章主要介绍了Zend Framework动作助手Url用法,结合实例形式分析了动作助手Url的功能,定义与相关使用技巧,需要的朋友可以参考下
本文实例讲述了Zend Framework动作助手Url用法。分享给大家供大家参考,具体如下
Url主要用于创建url;
public function simple($action, $controller = null, $module = null, array $params = null) public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) public function direct($action, $controller = null, $module = null, array $params = null)
<?php class IndexController extends Zend_Controller_Action { public function init() { / Initialize action controller here / } public function indexAction() { //$urlParser = $this->_helper->getHelper('UrlParser'); //var_dump($urlParser->parse('https://.jb51./article/80479.htm')); $url = $this->_helper->getHelper('Url'); $action = 'actionname'; $controller = 'controllername'; $module = 'modulename'; $params = array('param1'=>'中文参数'); var_dump($url->simple($action, $controller, $module, $params)); $urlOptions = array( 'action'=>$action, 'controller'=>$controller, 'module'=>$module, 'params'=>$params); var_dump($url->url($urlOptions)); var_dump($url->direct($action, $controller, $module, $params)); exit; } }
.localzend./helper_demo1/public/index
string(101) "/helper_demo1/public/modulename/controllername/actionname/param1/%E4%B8%AD%E6%96%87%E5%8F%82%E6%95%B0"
string(101) "/helper_demo1/public/modulename/controllername/actionname/params/%E4%B8%AD%E6%96%87%E5%8F%82%E6%95%B0"
string(101) "/helper_demo1/public/modulename/controllername/actionname/param1/%E4%B8%AD%E6%96%87%E5%8F%82%E6%95%B0"
实现源码如下
/ @see Zend_Controller_Action_Helper_Abstract / require_once 'Zend/Controller/Action/Helper/Abstract.php'; / Helper for creating URLs for redirects and other tasks @uses Zend_Controller_Action_Helper_Abstract @category Zend @package Zend_Controller @subpackage Zend_Controller_Action_Helper @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://.zend.) @license http://framework.zend./license/new-bsd New BSD License / class Zend_Controller_Action_Helper_Url extends Zend_Controller_Action_Helper_Abstract { / Create URL based on default route @param string $action @param string $controller @param string $module @param array $params @return string / public function simple($action, $controller = null, $module = null, array $params = null) { $request = $this->getRequest(); if (null === $controller) { $controller = $request->getControllerName(); } if (null === $module) { $module = $request->getModuleName(); } $url = $controller . '/' . $action; if ($module != $this->getFrontController()->getDispatcher()->getDefaultModule()) { $url = $module . '/' . $url; } if ('' !== ($baseUrl = $this->getFrontController()->getBaseUrl())) { $url = $baseUrl . '/' . $url; } if (null !== $params) { $paramPairs = array(); foreach ($params as $key => $value) { $paramPairs[] = urlencode($key) . '/' . urlencode($value); } $paramString = implode('/', $paramPairs); $url .= '/' . $paramString; } $url = '/' . ltrim($url, '/'); return $url; } / Assembles a URL based on a given route This method will typically be used for more plex operations, as it ties into the route objects registered with the router. @param array $urlOptions Options passed to the assemble method of the Route object. @param mixed $name The name of a Route to use. If null it will use the current Route @param boolean $reset @param boolean $encode @return string Url for the link href attribute. / public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) { $router = $this->getFrontController()->getRouter(); return $router->assemble($urlOptions, $name, $reset, $encode); } / Perform helper when called as $this->_helper->url() from an action controller Proxies to {@link simple()} @param string $action @param string $controller @param string $module @param array $params @return string / public function direct($action, $controller = null, $module = null, array $params = null) { return $this->simple($action, $controller, $module, $params); } }
更多关于zend相关内容感兴趣的读者可查看本站专题《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程