没有页眉/页脚的 CakePHP 页面

发布于 2024-10-29 02:53:23 字数 79 浏览 3 评论 0原文

在数据库中 blob 的下载页面中,如何才能不发送其他输出?现在它正在发送标头、调试信息和页脚。我如何才能做到不发送任何内容,而只是为了该视图?

In a download page for a blob from a database, how would I make it so that no other output is sent? Right now it's sending the header, debug info, and a footer. How do I make it so that none of that is sent, just for that view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜空下最亮的亮点 2024-11-05 02:53:23

您可以在布局文件夹中创建一个清晰的布局(例如 empty.ctp ),然后

<?php echo $content_for_layout ?>

在您获取 blob 数据的操作中使用该布局

$this->layout = 'empty.ctp';

并禁用调试,在您的 使用控制器。

Configure::write('debug',0);

如果您无法创建新的布局,您可以尝试

$this->layout = null;
$this->render("view_name");

you can create an clear layout (e.g. empty.ctp ) in you layouts folder, only with

<?php echo $content_for_layout ?>

and then in you action where you're getting your blob data use that layout

$this->layout = 'empty.ctp';

and also to disable debugging, in your controllers use

Configure::write('debug',0);

if you're unable to create new layout you could try this.

$this->layout = null;
$this->render("view_name");
︶ ̄淡然 2024-11-05 02:53:23

如果您使用它来下载文件,则应该使用 cakePHP 中的 Media 视图

http://book.cakephp.org/view/1094/Media-Views

    $this->view = 'Media';
    $params = array(
          'id' => 'example.zip',
          'name' => 'example',
          'download' => true,
          'extension' => 'zip',  // must be lower case
          'path' => APP . 'files' . DS   // don't forget terminal 'DS'
   );

If you're using this to download files, you should use the Media view in cakePHP

http://book.cakephp.org/view/1094/Media-Views

    $this->view = 'Media';
    $params = array(
          'id' => 'example.zip',
          'name' => 'example',
          'download' => true,
          'extension' => 'zip',  // must be lower case
          'path' => APP . 'files' . DS   // don't forget terminal 'DS'
   );
岁吢 2024-11-05 02:53:23

CakePhp 2.3 用户:

CakePhp 2.x 用户:

  • 使用“$this->viewClass”而不是“$this->view”

副本- 在任何控制器文件中粘贴准备好的完整解决方案:

<?php

public function download($file) {

    $fsTarget = APP.WEBROOT_DIR.DS.'files'.DS.$file; // files located in 'files' folder under webroot
    if (false == file_exists($fsTarget)){
            throw new NotFoundException(__('Invalid file'));
    }

    $pathinfo = pathinfo($fsTarget);

    $this->viewClass = 'Media';

    $params = array(
          'id' => $file,
          'name' => $pathinfo['filename'], // without extension
          'download' => true,
          'extension' => $pathinfo['extension'],  // must be lower case
          'path' => dirname($fsTarget) . DS // don't forget terminal 'DS'
   );
   $this->set($params);
}

希望这有帮助!

CakePhp 2.3 users :

CakePhp 2.x users :

  • use '$this->viewClass' instead of '$this->view'

copy-paste ready full solution, right in any controller file:

<?php

public function download($file) {

    $fsTarget = APP.WEBROOT_DIR.DS.'files'.DS.$file; // files located in 'files' folder under webroot
    if (false == file_exists($fsTarget)){
            throw new NotFoundException(__('Invalid file'));
    }

    $pathinfo = pathinfo($fsTarget);

    $this->viewClass = 'Media';

    $params = array(
          'id' => $file,
          'name' => $pathinfo['filename'], // without extension
          'download' => true,
          'extension' => $pathinfo['extension'],  // must be lower case
          'path' => dirname($fsTarget) . DS // don't forget terminal 'DS'
   );
   $this->set($params);
}

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文