Zend框架:打印消息,然后重定向


Zend framework : Print message and then redirect

我正在使用Zend框架版本1.11,试图打印消息,然后重定向到特定页面

echo "Great day";
$this->headMeta()->appendHttpEquiv('Refresh',
                                       '3;URL=http://localhost/index.php');

我引用了链接Zend HeadMeta Helper

但是它给出以下错误信息

 Fatal error: Uncaught exception 'Zend_Controller_Action_Exception'
 with message 'Method "headMeta" does not exist and was not trapped in __call()' 

你能帮助解决这个问题或建议一些其他的方法吗?

显然,您已经在控制器中编写了这段代码,但是headMeta()是一个视图帮助器,所以试试这个:

$this->view->headMeta()->appendHttpEquiv('Refresh','3;URL=http://localhost/index.php');

不要忘记在你的布局中添加这个:

echo $this->headMeta();

你可以通过简单的JavaScript实现。

echo <<<EOT
Good day.
<script type="text/javascript">
    setTimeout(function(){
        window.location.href = 'http://localhost/index.php';
    }, 2000/* set time here */);
</script>
EOT;

当试图从服务器端重定向时,我们不应该在报头之前写任何东西,也不应该在一些数据已经从服务器端写入之后,报头也将被发送。因此,服务器端代码将抛出错误。