您好,欢迎访问一九零五行业门户网

关于Zend Framework动作助手Url的用法

这篇文章主要介绍了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)
<?phpclass indexcontroller extends zend_controller_action{ public function init() { /* initialize action controller here */ } public function indexaction() { //$urlparser = $this->_helper->gethelper('urlparser'); //var_dump($urlparser->parse('//www.jb51.net/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; }}
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"
实现源码如下:
/** * @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 framework自定义helper类的相关知识
关于zend framework动作控制器的用法
关于zend framework中zend_db_table_rowset的用法
以上就是关于zend framework动作助手url的用法的详细内容。
其它类似信息

推荐信息