File indexing completed on 2024-12-29 05:27:31
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Controller 0017 * @subpackage Zend_Controller_Action_Helper 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Controller_Action_Helper_Abstract 0025 */ 0026 // require_once 'Zend/Controller/Action/Helper/Abstract.php'; 0027 0028 /** 0029 * Helper for creating URLs for redirects and other tasks 0030 * 0031 * @uses Zend_Controller_Action_Helper_Abstract 0032 * @category Zend 0033 * @package Zend_Controller 0034 * @subpackage Zend_Controller_Action_Helper 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Controller_Action_Helper_Url extends Zend_Controller_Action_Helper_Abstract 0039 { 0040 /** 0041 * Create URL based on default route 0042 * 0043 * @param string $action 0044 * @param string $controller 0045 * @param string $module 0046 * @param array $params 0047 * @return string 0048 */ 0049 public function simple($action, $controller = null, $module = null, array $params = null) 0050 { 0051 $request = $this->getRequest(); 0052 0053 if (null === $controller) { 0054 $controller = $request->getControllerName(); 0055 } 0056 0057 if (null === $module) { 0058 $module = $request->getModuleName(); 0059 } 0060 0061 $url = $controller . '/' . $action; 0062 if ($module != $this->getFrontController()->getDispatcher()->getDefaultModule()) { 0063 $url = $module . '/' . $url; 0064 } 0065 0066 if ('' !== ($baseUrl = $this->getFrontController()->getBaseUrl())) { 0067 $url = $baseUrl . '/' . $url; 0068 } 0069 0070 if (null !== $params) { 0071 $paramPairs = array(); 0072 foreach ($params as $key => $value) { 0073 $paramPairs[] = urlencode($key) . '/' . urlencode($value); 0074 } 0075 $paramString = implode('/', $paramPairs); 0076 $url .= '/' . $paramString; 0077 } 0078 0079 $url = '/' . ltrim($url, '/'); 0080 0081 return $url; 0082 } 0083 0084 /** 0085 * Assembles a URL based on a given route 0086 * 0087 * This method will typically be used for more complex operations, as it 0088 * ties into the route objects registered with the router. 0089 * 0090 * @param array $urlOptions Options passed to the assemble method of the Route object. 0091 * @param mixed $name The name of a Route to use. If null it will use the current Route 0092 * @param boolean $reset 0093 * @param boolean $encode 0094 * @return string Url for the link href attribute. 0095 */ 0096 public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) 0097 { 0098 $router = $this->getFrontController()->getRouter(); 0099 return $router->assemble($urlOptions, $name, $reset, $encode); 0100 } 0101 0102 /** 0103 * Perform helper when called as $this->_helper->url() from an action controller 0104 * 0105 * Proxies to {@link simple()} 0106 * 0107 * @param string $action 0108 * @param string $controller 0109 * @param string $module 0110 * @param array $params 0111 * @return string 0112 */ 0113 public function direct($action, $controller = null, $module = null, array $params = null) 0114 { 0115 return $this->simple($action, $controller, $module, $params); 0116 } 0117 }