web/lib/Zend/Controller/Action.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Controller
    16  * @package    Zend_Controller
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Action.php 22792 2010-08-05 18:30:27Z matthew $
    19  * @version    $Id: Action.php 24593 2012-01-05 20:35:02Z matthew $
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * @see Zend_Controller_Action_HelperBroker
    23  * @see Zend_Controller_Action_HelperBroker
    24  */
    24  */
    35 require_once 'Zend/Controller/Front.php';
    35 require_once 'Zend/Controller/Front.php';
    36 
    36 
    37 /**
    37 /**
    38  * @category   Zend
    38  * @category   Zend
    39  * @package    Zend_Controller
    39  * @package    Zend_Controller
    40  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    40  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    41  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    41  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    42  */
    42  */
    43 abstract class Zend_Controller_Action implements Zend_Controller_Action_Interface
    43 abstract class Zend_Controller_Action implements Zend_Controller_Action_Interface
    44 {
    44 {
    45     /**
    45     /**
   503         if ($this->getRequest()->isDispatched()) {
   503         if ($this->getRequest()->isDispatched()) {
   504             if (null === $this->_classMethods) {
   504             if (null === $this->_classMethods) {
   505                 $this->_classMethods = get_class_methods($this);
   505                 $this->_classMethods = get_class_methods($this);
   506             }
   506             }
   507 
   507 
   508             // preDispatch() didn't change the action, so we can continue
   508             // If pre-dispatch hooks introduced a redirect then stop dispatch
   509             if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
   509             // @see ZF-7496
   510                 if ($this->getInvokeArg('useCaseSensitiveActions')) {
   510             if (!($this->getResponse()->isRedirect())) {
   511                     trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
   511                 // preDispatch() didn't change the action, so we can continue
       
   512                 if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
       
   513                     if ($this->getInvokeArg('useCaseSensitiveActions')) {
       
   514                         trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
       
   515                     }
       
   516                     $this->$action();
       
   517                 } else {
       
   518                     $this->__call($action, array());
   512                 }
   519                 }
   513                 $this->$action();
       
   514             } else {
       
   515                 $this->__call($action, array());
       
   516             }
   520             }
   517             $this->postDispatch();
   521             $this->postDispatch();
   518         }
   522         }
   519 
   523 
   520         // whats actually important here is that this action controller is
   524         // whats actually important here is that this action controller is
   577      * @param mixed $default
   581      * @param mixed $default
   578      * @return mixed
   582      * @return mixed
   579      */
   583      */
   580     protected function _getParam($paramName, $default = null)
   584     protected function _getParam($paramName, $default = null)
   581     {
   585     {
       
   586         return $this->getParam($paramName, $default);
       
   587     }
       
   588 
       
   589     /**
       
   590      * Gets a parameter from the {@link $_request Request object}.  If the
       
   591      * parameter does not exist, NULL will be returned.
       
   592      *
       
   593      * If the parameter does not exist and $default is set, then
       
   594      * $default will be returned instead of NULL.
       
   595      *
       
   596      * @param string $paramName
       
   597      * @param mixed $default
       
   598      * @return mixed
       
   599      */
       
   600     public function getParam($paramName, $default = null)
       
   601     {
   582         $value = $this->getRequest()->getParam($paramName);
   602         $value = $this->getRequest()->getParam($paramName);
   583 		 if ((null === $value || '' === $value) && (null !== $default)) {
   603          if ((null === $value || '' === $value) && (null !== $default)) {
   584             $value = $default;
   604             $value = $default;
   585         }
   605         }
   586 
   606 
   587         return $value;
   607         return $value;
   588     }
   608     }
   591      * Set a parameter in the {@link $_request Request object}.
   611      * Set a parameter in the {@link $_request Request object}.
   592      *
   612      *
   593      * @param string $paramName
   613      * @param string $paramName
   594      * @param mixed $value
   614      * @param mixed $value
   595      * @return Zend_Controller_Action
   615      * @return Zend_Controller_Action
       
   616      * @deprecated Deprecated as of Zend Framework 1.7. Use
       
   617      *             setParam() instead.
   596      */
   618      */
   597     protected function _setParam($paramName, $value)
   619     protected function _setParam($paramName, $value)
       
   620     {
       
   621         return $this->setParam($paramName, $value);
       
   622     }
       
   623 
       
   624     /**
       
   625      * Set a parameter in the {@link $_request Request object}.
       
   626      *
       
   627      * @param string $paramName
       
   628      * @param mixed $value
       
   629      * @return Zend_Controller_Action
       
   630      */
       
   631     public function setParam($paramName, $value)
   598     {
   632     {
   599         $this->getRequest()->setParam($paramName, $value);
   633         $this->getRequest()->setParam($paramName, $value);
   600 
   634 
   601         return $this;
   635         return $this;
   602     }
   636     }
   605      * Determine whether a given parameter exists in the
   639      * Determine whether a given parameter exists in the
   606      * {@link $_request Request object}.
   640      * {@link $_request Request object}.
   607      *
   641      *
   608      * @param string $paramName
   642      * @param string $paramName
   609      * @return boolean
   643      * @return boolean
       
   644      * @deprecated Deprecated as of Zend Framework 1.7. Use
       
   645      *             hasParam() instead.
   610      */
   646      */
   611     protected function _hasParam($paramName)
   647     protected function _hasParam($paramName)
       
   648     {
       
   649         return $this->hasParam($paramName);
       
   650     }
       
   651 
       
   652     /**
       
   653      * Determine whether a given parameter exists in the
       
   654      * {@link $_request Request object}.
       
   655      *
       
   656      * @param string $paramName
       
   657      * @return boolean
       
   658      */
       
   659     public function hasParam($paramName)
   612     {
   660     {
   613         return null !== $this->getRequest()->getParam($paramName);
   661         return null !== $this->getRequest()->getParam($paramName);
   614     }
   662     }
   615 
   663 
   616     /**
   664     /**
   617      * Return all parameters in the {@link $_request Request object}
   665      * Return all parameters in the {@link $_request Request object}
   618      * as an associative array.
   666      * as an associative array.
   619      *
   667      *
   620      * @return array
   668      * @return array
       
   669      * @deprecated Deprecated as of Zend Framework 1.7. Use
       
   670      *             getAllParams() instead.
   621      */
   671      */
   622     protected function _getAllParams()
   672     protected function _getAllParams()
       
   673     {
       
   674         return $this->getAllParams();
       
   675     }
       
   676 
       
   677     /**
       
   678      * Return all parameters in the {@link $_request Request object}
       
   679      * as an associative array.
       
   680      *
       
   681      * @return array
       
   682      */
       
   683     public function getAllParams()
   623     {
   684     {
   624         return $this->getRequest()->getParams();
   685         return $this->getRequest()->getParams();
   625     }
   686     }
   626 
   687 
   627 
   688 
   648      * @param string $action
   709      * @param string $action
   649      * @param string $controller
   710      * @param string $controller
   650      * @param string $module
   711      * @param string $module
   651      * @param array $params
   712      * @param array $params
   652      * @return void
   713      * @return void
       
   714      * @deprecated Deprecated as of Zend Framework 1.7. Use
       
   715      *             forward() instead.
   653      */
   716      */
   654     final protected function _forward($action, $controller = null, $module = null, array $params = null)
   717     final protected function _forward($action, $controller = null, $module = null, array $params = null)
       
   718     {
       
   719         $this->forward($action, $controller, $module, $params);
       
   720     }
       
   721 
       
   722     /**
       
   723      * Forward to another controller/action.
       
   724      *
       
   725      * It is important to supply the unformatted names, i.e. "article"
       
   726      * rather than "ArticleController".  The dispatcher will do the
       
   727      * appropriate formatting when the request is received.
       
   728      *
       
   729      * If only an action name is provided, forwards to that action in this
       
   730      * controller.
       
   731      *
       
   732      * If an action and controller are specified, forwards to that action and
       
   733      * controller in this module.
       
   734      *
       
   735      * Specifying an action, controller, and module is the most specific way to
       
   736      * forward.
       
   737      *
       
   738      * A fourth argument, $params, will be used to set the request parameters.
       
   739      * If either the controller or module are unnecessary for forwarding,
       
   740      * simply pass null values for them before specifying the parameters.
       
   741      *
       
   742      * @param string $action
       
   743      * @param string $controller
       
   744      * @param string $module
       
   745      * @param array $params
       
   746      * @return void
       
   747      */
       
   748     final public function forward($action, $controller = null, $module = null, array $params = null)
   655     {
   749     {
   656         $request = $this->getRequest();
   750         $request = $this->getRequest();
   657 
   751 
   658         if (null !== $params) {
   752         if (null !== $params) {
   659             $request->setParams($params);
   753             $request->setParams($params);
   678      * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
   772      * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
   679      *
   773      *
   680      * @param string $url
   774      * @param string $url
   681      * @param array $options Options to be used when redirecting
   775      * @param array $options Options to be used when redirecting
   682      * @return void
   776      * @return void
       
   777      * @deprecated Deprecated as of Zend Framework 1.7. Use
       
   778      *             redirect() instead.
   683      */
   779      */
   684     protected function _redirect($url, array $options = array())
   780     protected function _redirect($url, array $options = array())
   685     {
   781     {
       
   782         $this->redirect($url, $options);
       
   783     }
       
   784 
       
   785     /**
       
   786      * Redirect to another URL
       
   787      *
       
   788      * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
       
   789      *
       
   790      * @param string $url
       
   791      * @param array $options Options to be used when redirecting
       
   792      * @return void
       
   793      */
       
   794     public function redirect($url, array $options = array())
       
   795     {
   686         $this->_helper->redirector->gotoUrl($url, $options);
   796         $this->_helper->redirector->gotoUrl($url, $options);
   687     }
   797     }
   688 }
   798 }