Zend Framework Action Assistant URL usage detailed _php instance

Source: Internet
Author: User
Tags urlencode zend zend framework

This example describes the Zend Framework Action Assistant URL usage. Share to everyone for your reference, specific as follows:

URLs are primarily used to create URLs;

The public function is simple ($action, $controller = null, $module = NULL, array $params = null) The public
function URL ($urlOpti ONS = Array (), $name = null, $reset = False, $encode = true) public
function Direct ($action, $controller = null, $modu Le = null, array $params = null)

<?php
class 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.jb51.net/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 (/helper_demo1/public/modulename/controllername/actionname/param1/%e4%b8%ad%e6%96%87%e5%8f%82%e6%95) %b0 "
String (/helper_demo1/public/modulename/controllername/actionname/params/%e4%b8%ad%e6%96%87%e5%8f%82%e6%95) %b0 "
String (/helper_demo1/public/modulename/controllername/actionname/param1/%e4%b8%ad%e6%96%87%e5%8f%82%e6%95) %b0 "

Implementation of the source code is as follows:

/** * @see zend_controller_action_helper_abstract/require_once ' zend/controller/action/helper/abstract.php '; /** * Helper for creating URL for redirects and other tasks * * @uses zend_controller_action_helper_abstract * @ca Tegory Zend * @package zend_controller * @subpackage zend_controller_action_helper * @copyright Copyright (c) 2005-20 One Zend Technologies USA INC (http://www.zend.com) * @license Http://framework.zend.com/license/new-bsd New BSD Licen SE */class Zend_controller_action_helper_url extends Zend_controller_action_helper_abstract {/** * Create URL Base D on Default route * * @param string $action * @param string $controller * @param string $module * @param a  Rray $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 would typically is used for more complex
   NS, 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 would use the current Route * @param boolean $reset * @param a Boolean $encode * @return string Url for T
   He 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 a action controller * * proxies to {@li NK 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 = nul
  L) {return $this->simple ($action, $controller, $module, $params);

 }
}

More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.