我正在努力学习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;
}
}
Run Code Online (Sandbox Code Playgroud)
但我一直得到这个致命的错误:
( ! ) 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
Run Code Online (Sandbox Code Playgroud)
我一直在寻找这个错误以及在ZF2中进行ajax调用的最佳方法,但是ZF1或ZF2测试结果不断出现并且不起作用.感谢您提供任何建议.
我有一个带有顶部导航栏的站点布局,我需要将类设置为活动,具体取决于当用户单击不同页面时更改的控制器.
则须─> index.phtml
<li class='<?php echo (isset($this->controllerName) && $this->controllerName == 'about') ? 'active' : '' ?>'><a href="/about">About Us</a></li>
<li class='<?php echo (isset($this->controllerName) && $this->controllerName == 'services') ? 'active' : '' ?>'><a href="/services">Member Sevices</a></li>
Run Code Online (Sandbox Code Playgroud)
我希望Phalcon有一个视图功能,或者我可以把它放在引导程序中,所以它适用于所有页面而我不得不记住在每个Controller中手动设置controllerName变量.