【问题标题】:How it's possible to disable rendering layout in case of xmlhttprequest in phalcon framework?如果在 phalcon 框架中使用 xmlhttprequest,如何禁用渲染布局?
【发布时间】:2012-12-05 05:10:18
【问题描述】:

如何禁用布局渲染?

暂时我可以通过这种方式检测到请求是通过 jQuery 发出的:

public function initialize()
{
    if (!$this->request->isAjax()) {
        // disable layout here... how?
    }
}

可以在全球范围内完成吗?

所有控件的处理 ajax 请求的代码都是相同的,有没有办法为整个应用程序全局定义此行为规则?

【问题讨论】:

  • 什么是初始化?这是在您的基本控制器类中还是什么?
  • @Koveras 我已经扩展了 phalcon\mvc\controller 并定义了这个函数来处理 ajax 请求。请看docs.phalconphp.com/en/latest/reference/…

标签: php layout controller xmlhttprequest phalcon


【解决方案1】:
public function initialize()
{
    if (!$this->request->isAjax()) 
    {
        // disable layout here... how?
        $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
    }
}

你也可以通过调用来禁用自动渲染

$this->view->disable();

【讨论】:

  • $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW) 在这里会更正确..但非常感谢您的想法:)
猜你喜欢
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多