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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵