加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Zend Framework动作助手Url用法详解

发布时间:2020-12-12 21:22:10 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解Zend Framework动作助手Url用法。供大家参考研究具体如下: Url主要用于创建url; _helper->getHelper('UrlParser'); //var_dump($urlParser->parse('//www.jb51.cc/article/80479.htm')); $url = $this->_helper->getHelper('Url');

本篇章节讲解Zend Framework动作助手Url用法。分享给大家供大家参考,具体如下:

Url主要用于创建url;

_helper->getHelper('UrlParser'); //var_dump($urlParser->parse('//www.52php.cn/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,$params)); exit; } }

www.localzend.com/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"

实现源码如下:

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(),$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,array $params = null) { return $this->simple($action,$params); } }

更多关于zend相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《》

希望本文所述对大家PHP程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读