ZendFramework action assistant Url usage details, zendframework_PHP tutorial

Source: Internet
Author: User
Tags zend framework
Detailed description of ZendFramework action assistant Url usage, zendframework. Detailed description of ZendFramework action assistant Url usage. zendframework this article describes the ZendFramework action assistant Url usage. The Url is mainly used to create Zend Framework action assistant Url usage details, zendframework

This example describes the Zend Framework action assistant Url usage. We will share this with you for your reference. The details are as follows:

URLs are mainly used to create URLs;

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 ('http: // www.bkjia.com/article/80479.htm ')); $ url = $ this-> _ helper-> getHelper ('URL'); $ action = 'actionname'; $ controller = 'controllername'; $ module = 'modulename '; $ params = array ('param1' => 'Chinese parameters'); 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% E5 % 8F % 87% E6 % 82% B0"
String (101) "/helper_demo1/public/modulename/controllername/actionname/params/% E4 % B8 % AD % E6 % 96% E5 % 8F % 87% E6 % 82% B0"
String (101) "/helper_demo1/public/modulename/controllername/actionname/param1/% E4 % B8 % AD % E6 % 96% E5 % 8F % 87% E6 % 82% B0"

The source code is as follows:

/** * @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);  }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.