- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在努力学习 ZF2。我有一个使用 Ajax 获取一些数据的页面。 ZF2 函数应返回一个 JSON 字符串。
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
class DocumentsController extends AbstractActionController {
public function indexAction() {
}
public function getTreeDataAction() {
$json = new JsonModel(array(
'title' => 'Some Title'
));
return $json;
}
}
但我一直收到这个 fatal error :
( ! ) Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "application/documents/get-tree-data"; resolver could not resolve to a file' in ../vendor/ZF2/library/Zend/View/Renderer/PhpRenderer.php on line 451
我一直在寻找这个错误以及在 ZF2 中进行 ajax 调用的最佳方法,但是 ZF1 或 ZF2 beta 的结果不断出现并且不起作用。感谢您提供任何建议。
最佳答案
嗯,这个错误几乎意味着它试图访问默认渲染策略,这很奇怪......你是否将 JsonStrategy 添加到你的 view_manager?
//module.config.php
return array(
'view_manager' => array(
'strategies' => array(
'ViewJsonStrategy',
),
),
)
此外,为您的 ajax 调用设置正确的接受 header 以仅接受 application/json
内容类型是个好主意。有了这一套,它应该可以正常工作。出于好奇,modules/__NAMESPACE__/view/__namespace__/documents/get-tree-data.phtml
是否存在?
关于php - ZF2 : Return JSON only for Ajax Call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12612414/
当我像这样使用 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 =
我是一名优秀的程序员,十分优秀!