- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
使用 PHP Zend Framework 2.0.2,我在 AJAX 调用后返回 JSON 数据。显然,Internet Explorer 9 想要下载数据而不是将其返回给调用 Javascript 方法。
类似 this one 的帖子和 this one说要使用 Content-Type: text/plain
而不是 Content-Type: application/json
,但是我如何使用 ZF2 的 JsonModel 来做到这一点?我是新手...
我想我必须在 setOptions()
数组中设置一些东西,但是什么?
public function testJsonAction()
{
$jsonResponse = new JsonModel(array('success' => false));
$jsonResponse->setOptions(array(
// ** Should I put something here? What? **
));
return $jsonResponse;
}
我试过使用这些:
$this->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'text/plain');
$this->getResponse()->getHeaders()->addHeaderLine('Content-Disposition', 'inline; filename="textdata.json"');
但它不会更改响应 header 中的 HTTP Content-Type:
Key Value
Response HTTP/1.1 200 OK
Content-Type application/json
Server Microsoft-IIS/7.5
X-Powered-By PHP/5.3.13
Set-Cookie ZDEDebuggerPresent=php,phtml,php3; path=/
Content-Disposition inline; filename="textdata.json"
X-Powered-By ASP.NET
Date Wed, 10 Oct 2012 13:19:42 GMT
Content-Length 17
感谢您的帮助!
最佳答案
因为当\Zend\Mvc\MvcEvent::EVENT_RENDER 事件发生时,JsonStrategy 将再次改变内容类型。源代码在
Zend\View\Strategy\JsonStrategy->injectResponse();
因此,为了将内容类型替换为您的内容类型,您需要使用 EventManager 在 JsonStrategy 注入(inject)后注入(inject)您的自定义 header 。
在您的 Controller 中尝试以下代码:
$this->getServiceLocator()->get('Application')->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function($event){
$event->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'text/plain');
}, -10000);
关于php - 如何告诉 ZF2 的 JsonModel 返回 text/plain 而不是 application/json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12820415/
当我像这样使用 zend CLI 创建表单时,会生成一个表单并将其添加到表单文件夹中。 zf create form MyForm 我有一个自定义类,我想以相同的方式为其创建一个自定义命令,并希望查看
我有一个以 user_id 作为主键的用户表和一个以 user_date_id 作为主键的 user_dates 表,user_id 链接到用户表以及 start_date 和 end_date 字段
我得到了这个代码 $select ->from(array("e" => "embarcacoes")) ->join(array("i
我遇到了 PHP 和 Zend Framework 的这个小问题。 我使用 apt-get install libzend-framework-php 安装了 ZF它还安装了二进制 zf.sh和 ze
我有一小段(x86)程序集,我试图弄清楚它的作用。 ... 6: 81 ec 00 01 00 00 sub $0x100, %esp c: 31 c9
我正在将 ZF 用于 MVC 应用程序,并且对我的代码应该如何构建感到非常困惑。 我有一个过程应用程序,它基本上是 1 个巨大的长文件,其中包含我希望我的应用程序执行的所有功能......例如:get
我的身份验证适配器如下所示 $authAdapter->setTableName('register') ->setIdentityColumn('u
我们最近开始使用 Doctrine 2.2 和 Zend Framework 2 的一部分,以努力改进组织、减少重复等。今天,我开始提出实现服务层的想法,以充当我们的 Controller 和 Doc
我是 phpunit 测试的新手。任何人都可以帮助我如何测试图像中下面的行。 到目前为止我的测试是: public function testCanSendEmail() { $formDat
我正在尝试写这个,用 zf select 查询但没有成功 SELECT * FROM `subscribers` WHERE id IN (Select subscriber_id From gs_r
我正在使用 Zend Framework 的 Zend_Db_Table从数据库中获取数据的类。 我想通过向表中添加一些内容来“优化”我从表中获取的每一行。在一个普通的旧 SQL 查询中,我会写例如。
我正在尝试使用 Zend_Db 进行与此类似的更新: UPDATE `TABLE` SET column = column + 'new value' WHERE foo = 'bar' 你们
cmpxchg 的操作伪代码如下(Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 2A: Instructi
我正在使用具有 REST API 的 ZF 开发应用程序。一切都很顺利,除了我的 XML 在开头有一个空白字符,所以 XML 打破了在开头有 XML 声明的规则。我正在尝试使用 javascript/
这段代码是否给了我最后插入的记录 id,即使在重载页面上? db = Zend_Db_Table::getDefaultAdapter(); $db->insert($this->_name,
为什么 lists:zf/2 是 Erlang 中 filtermap/2 的别名? 这是列表中未记录但已导出的函数:模块。这是实现: zf(F, L) -> filtermap(F, L).
我正在 x86 上调试我的代码,问题追溯到 AND 指令如果结果不为零,有时不会清除 ZF 标志。这是有问题的代码: 0257A9F9 mov edx,dword ptr [ecx+
我需要使用一些没有 GCC 内在函数的 x86 指令,例如 BSF 和 BSR。使用 GCC 内联汇编,我可以编写如下内容 __INTRIN_INLINE unsigned char bsf64(un
我在将复选框包装到标签中时遇到了 Zend 装饰器 (ZF1) 的一些问题。 在我的表格中,我有一些非常简单的东西: $remember = new Zend_Form_Element_Checkbo
我有一个简单的查询,但我一辈子也想不通。 我有一个包含“thread_id”和“messages”列的(简化的)“messages”表 我还有一个线程列表,每个线程需要 10 个结果。 $list =
我是一名优秀的程序员,十分优秀!