【问题标题】:Zend framework : Print message and then redirectZend 框架:打印消息然后重定向
【发布时间】:2014-06-18 16:15:32
【问题描述】:

我正在使用 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()' 

您能否帮助解决问题或建议其他方法来解决此问题?

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

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

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

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

    echo $this->headMeta();
    

    【讨论】:

      【解决方案2】:

      您可以通过简单的 JavaScript 做到这一点。

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

      在尝试从服务器端重定向时,我们不应该在标头之前写入任何内容,并且在一些数据已经从服务器端写入并且标头也将被发送之后。所以,服务器端代码会抛出错误。

      【讨论】:

        猜你喜欢
        • 2012-05-15
        • 1970-01-01
        • 1970-01-01
        • 2014-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多