Zend Framework Action Assistant URL usage, zendframework_php tutorial

Source: Internet
Author: User
Tags urlencode zend framework

Zend Framework Action Assistant URL usage details, zendframework


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

URLs are primarily used to create URLs;

The public function is simple ($action, $controller = null, $module = NULL, array $params = null), and the public is a 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 parameter ');    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 "

Realize the source code 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 Ze nd * @package zend_controller * @subpackage zend_controller_action_helper * @copyright Copyright (c) 2005-2011 Zend Techn Ologies USA Inc. (http://www.zend.com) * @license HTTP://FRAMEWORK.ZEND.COM/LICENSE/NEW-BSD new BSD license */class Zen   D_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 would 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 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 boolean $encode * @return string Url for the link href attribute. */Public Function URL ($urlOptions = Array (), $name = null, $reset = False, $encode = True) {$router = $this->get    Frontcontroller ()->getrouter ();  Return $router->assemble ($urlOptions, $name, $reset, $encode); }/** * Perform helper when called as $this->_helper->url () from a action controller * Proxies to {@link s   Imple ()} * * @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) {RET  Urn $this->simple ($action, $controller, $module, $params); }}

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Controller usage Analysis of MVC Framework for Zend Framework Tutorial
    • Zend Framework Tutorial's routing function zend_controller_router detailed
    • Zend Framework Tutorial Zend_controller_plugin plugin Usage
    • Package Zend_controller_response Example of response object for Zend Framework tutorial
    • Package Zend_controller_request example of request object for Zend Framework tutorial
    • Zend Framework Tutorial Action base class Zend_controller_action detailed
    • Zend Framework Tutorial Distributor Zend_controller_dispatcher Usage
    • Zend Framework Tutorial Front Controller Zend_controller_front Usage
    • Zend Framework Action Assistant Redirector usage examples
    • Zend Framework Action Helper JSON usage example analysis
    • Zend Framework Action Assistant Flashmessenger usage
    • Examples of resource autoloading usages of the Zend framework tutorial

http://www.bkjia.com/PHPjc/1106898.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106898.html techarticle Zend Framework Action Assistant URL usage, zendframework This article describes the Zend Framework Action helper URL usage. Share to everyone for reference, as follows: URL is mainly used to create ...

  • Related Article

    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.