dtpk04526211 2016-08-08 13:57
浏览 65
已采纳

Phalcon PhP - 如何禁用动作的主要布局

I'm creating a action in one of my phalcon controller which will be used to generate a print version of a page. Here is my print.volt layout:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Print</title>
</head>
<body>
<!-- Begin page content -->
<div class="container">
    {% block content %}{% endblock %}
</div>
</body>
</html>

And my view:

{% extends "layouts/print.volt" %}
{% block content %}
    HERE
    <script type="text/javascript">
        window.print();
    </script>
{% endblock %}

It is working, but my problem is that the content generated is inserted inside another layout that has the {{ content() }} tag. At the end O get a page with all the website menus, my print.volt and my view. I would like to know how can I get just the view inserted inside the print.volt, without the master layout. How can I disable this behavior?

Thanks for any help!

  • 写回答

1条回答 默认 最新

  • doujiu8479 2016-08-08 14:03
    关注

    Two options come to mind.

    1) Use Simple view, which can render a template without the layout:

    $view = new \Phalcon\Mvc\View\Simple();
    $view->setViewsDir('PATH_TO_YOUR_VIEWS');
    $html = $view->render('template-name', $params);
    

    This option is also really handy when generating HTML for email sending.

    2) Disable the layout for the current Controller::method

    $this->view->setLayout('');
    

    3) Update: Timothy recommended an alternative to (2)

    $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办