本文实例讲述了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)
<"/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://www.zend.com) * @license http://framework.zend.com/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 complex 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相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“Zend Framework动作助手Url用法详解”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?