标题: Zend Framework中怎样使用_redirect()传递参数?
vice-captain
新手上路
Rank: 1



UID 1755
精华 0
积分 0
帖子 1
翻译 0
原创 0
阅读权限 10
注册 2008-8-3
状态 离线
发表于 2008-8-5 12:31  资料  短消息  加为好友 
Zend Framework中怎样使用_redirect()传递参数?

在Zend Framework开发的Application中,我需要使用_redirect()函数,该函数的原型是:
void _redirect(string url,array $options),如果我声明一个数据如下:
array(
      'message' => 'a',
      'name'     => 'b,
);
那么在url指定的方法中,我应该怎样来获取传递的数组以及各个元素的值呢?请高手指点!谢谢!^_^

顶部
jasonqi
PHPEye Developer
Rank: 8Rank: 8



UID 275
精华 0
积分 0
帖子 74
翻译 0
原创 0
阅读权限 1
注册 2007-8-11
状态 离线
发表于 2008-8-5 12:49  资料  短消息  加为好友 
似乎不支持你的数组,这里是源代码:

PHP代码如下:
/**
     * Redirect to another URL
     *
     * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
     *
     * @param string $url
     * @param array $options Options to be used when redirecting
     * @return void
     */
    
protected function _redirect($url, array $options = array())
    {
        
$this->_helper->redirector->gotoUrl($url$options);
    }





PHP代码如下:
/**
     * Set a redirect URL string
     *
     * By default, emits a 302 HTTP status header, prepends base URL as defined
     * in request object if url is relative, and halts script execution by
     * calling exit().
     *
     * $options is an optional associative array that can be used to control
     * redirect behaviour. The available option keys are:
     * - exit: boolean flag indicating whether or not to halt script execution when done
     * - prependBase: boolean flag indicating whether or not to prepend the base URL when a relative URL is provided
     * - code: integer HTTP status code to use with redirect. Should be between 300 and 307.
     *
     * _redirect() sets the Location header in the response object. If you set
     * the exit flag to false, you can override this header later in code
     * execution.
     *
     * If the exit flag is true (true by default), _redirect() will write and
     * close the current session, if any.
     *
     * @param  string $url
     * @param  array  $options
     * @return void
     */
    
public function setGotoUrl($url, array $options = array())
    {
        
// prevent header injections
        
$url str_replace(array("\n""\r"), ''$url);

        
$exit        $this->getExit();
        
$prependBase $this->getPrependBase();
        
$code        $this->getCode();
        if (
null !== $options) {
            if (isset(
$options['exit'])) {
                
$this->setExit(($options['exit']) ? true false);
            }
            if (isset(
$options['prependBase'])) {
                
$this->setPrependBase(($options['prependBase']) ? true false);
            }
            if (isset(
$options['code'])) {
                
$this->setCode($options['code']);
            }
        }

        
// If relative URL, decide if we should prepend base URL
        
if (!preg_match('|^[a-z]+://|'$url)) {
            
$url $this->_prependBase($url);
        }

        
$this->_redirect($url);
    }



重点是:

     * $options is an optional associative array that can be used to control
     * redirect behaviour. The available option keys are:
     * - exit: boolean flag indicating whether or not to halt script execution when done
     * - prependBase: boolean flag indicating whether or not to prepend the base URL when a relative URL is provided
     * - code: integer HTTP status code to use with redirect. Should be between 300 and 307.

顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2009-1-10 05:58

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.597343 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver