在zend框架中将变量设置为404 [英] Set variables to 404 in zend framework 2

查看:156
本文介绍了在zend框架中将变量设置为404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中,我在If语句之后抛出一个404响应,例如:

  if($ foo){ 
$ this-> getResponse() - > setStatusCode(404);
return;
}

然后,我想向我的404页面发送一些变量。在我看来,我想这样做:

  $ this-> getResponse() - > setVariables ('foo'=>'bar','baz'=>'bop')); 
$ this-> getResponse() - > setStatusCode(404);
return;

这不是好的解决方案,所以我该怎么办?

$ b $


$ b

谢谢

解决方案

哦上帝。



我很蠢。



解决方案:

  if($ foo){
$ this-> getResponse() - > setStatusCode 404);
return array('myvar'=>'test');
}

在404.phtml中:

 <?php echo $ this-> myvar; > 


In my controller I throw a 404 response after an If statement, something like that :

    if ($foo) {
        $this->getResponse()->setStatusCode(404);
        return; 
    }

Then, I would like to send some variables to my 404 page. In my mind, I want to do something like that :

    $this->getResponse()->setVariables(array('foo' => 'bar', 'baz' => 'bop'));
    $this->getResponse()->setStatusCode(404);
    return; 

It's not the good solution, so how I have to do that ?

And after, how to get these variables in my 404 view ?

Thank you

解决方案

Oh god..

I was so dumb

Solution :

if ($foo) {
    $this->getResponse()->setStatusCode(404);
    return array('myvar' => 'test');
}

In 404.phtml :

<?php echo $this->myvar; ?>

这篇关于在zend框架中将变量设置为404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆