PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Accessors

A number of objects and variables are registered with the object, and each has accessor methods.

  • Request Object: getRequest() may be used to retrieve the request object used to call the action.

  • Response Object: getResponse() may be used to retrieve the response object aggregating the final response. Some typical calls might look like:

    <?php
    $this
    ->getResponse()->setHeader('Content-Type''text/xml');
    $this->getResponse()->appendBody($content);
  • Invocation Arguments: the front controller may push parameters into the router, dispatcher, and action controller. To retrieve these, use getInvokeArg($key); alternatively, fetch the entire list using getInvokeArgs().

  • Request parameters: The request object aggregates request parameters, such as any _GET or _POST parameters, or user parameters specified in the URL's path information. To retrieve these, use _getParam($key) or _getAllParams(). You may also set request parameters using _setParam(); this is useful when forwarding to additional actions.

    To test whether or not a parameter exists (useful for logical branching), use _hasParam($key).

    Note

    _getParam() may take an optional second argument containing a default value to use if the parameter is not set or is empty. Using it eliminates the need to call _hasParam() prior to retrieving a value:

    <?php
    // Use default value of 1 if id is not set
    $id $this->_getParam('id'1);

    // Instead of:
    if ($this->_hasParam('id') {
        
    $id $this->_getParam('id');
    } else {
        
    $id 1;
    }

Zend Framework