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 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画