我在ZF2 $this->_helper->viewRenderer->setNoRender(); or (true)
沒有運氣禁用視圖掙扎,因爲它總是說,有在ZF2
PHP Fatal error: Call to a member function setNoRender() on a non-object in ../module/Location/src/Location/Controller/LocationController.php on line 190
我在ZF2 $this->_helper->viewRenderer->setNoRender(); or (true)
沒有運氣禁用視圖掙扎,因爲它總是說,有在ZF2
PHP Fatal error: Call to a member function setNoRender() on a non-object in ../module/Location/src/Location/Controller/LocationController.php on line 190
要完全禁用的觀點,從一個控制器動作中,你應該返回一個Response對象:
<?php
namespace SomeModule\Controller;
use Zend\Mvc\Controller\ActionController,
Zend\View\Model\ViewModel;
class SomeController extends ActionController
{
public function someAction()
{
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent("Hello World");
return $response;
}
}
要禁用佈局,並只呈現這個動作的視圖模型模板,你可以這樣做:
public function anotherAction()
{
$result = new ViewModel();
$result->setTerminal(true);
return $result;
}
$this->_helper
不ZF2可用,但禁用的視圖,你可以這樣做:
$this->broker("ViewRenderer")->setNoRender();
或
$this->broker->load("ViewRenderer")->setNoRender();
對不起,我已經嘗試這一點,但總是**無法找到與「視圖解析器」關聯的類**錯誤 – mahi 2012-02-08 15:30:03
也發現了這個沒有工作 - 這兩種方法 – 2012-02-11 19:19:01
的ZF2在很大程度上處於開發階段,沒有瓜爾保障人們可以製成現在的工作方式,將在ZF2達到一個穩定的狀態,它的工作方式。
然而,從Zend的\ MVC中的新視圖層最近合併,這使返回視圖模型與視圖相關的信息來渲染視圖的選項。要禁用視圖渲染,直接返回響應,所以認爲不會呈現在所有可以快捷的調度。
public function somethingAction()
{
// Do some intelligent work
return $this->getResponse();
}
只是在方法返回',它不會自動加載查看模板
public function goAction()
{
return '';
}
公共功能的indexAction(){
$news = $this->em->getRepository('Admin\Model\News'); foreach ($news->findAll() as $new) { $res = $this->getResponse()->setContent($new->toXml()); } return $res; }
我發現禁用佈局的簡單解決方案。在我ajaxAction
public function ajaxAction()
{
if ($this->getRequest()->isXmlHttpRequest()) {
$this->layout('layout/ajax-layout');
}
}
而且在\module\Application\view\layout\ajax-layout.phtml
<?php echo $this->content; ?>
我要說的只是禁用佈局僅
$viewModel = new ViewModel();
$viewModel->setTerminal(true);
return $viewModel;
和呼應你的JSON到您的視圖文件...
public function testAction()
{
return false;
}
SI mply返回false。
你可以這樣做,使用控制檯模式,或隨意殺死執行。
<?php
namespace SomeModule\Controller;
use Zend\Mvc\Controller\ActionController;
use Zend\View\Model\ConsoleModel; // if use ConsoleMode
use Zend\View\Model\JsonModel; // if use JSON
class SomeController extends ActionController
{
public function someAction() {
return new ConsoleModel(array(
'message' => 'Hello World',
));
}
// Json Method
public function jsonAction() {
return new JsonModel(array(
'message' => 'Hello World',
));
}
// This is really exaggerated, but it is quite effective.
public function killAction() {
echo 'Hello World';
exit;
}
}
鑑於使用: some.phtml
<?php
echo $message;
JSON。PHTML
<?php
echo $message;
太感謝你了! :) – ufk 2012-06-30 12:05:29