WkHtmlToPdf 组件,身份验证问题

发布于 2024-10-20 07:37:00 字数 1049 浏览 1 评论 0原文

我正在尝试使用 WkHtmlToPdf 组件,它当遇到生成 pdf 文件的问题时,似乎是一个不错的工具。

但是 - 我无法让它与身份验证组件一起使用。问题是我总是将登录页面生成为 pdf 格式。我已记录,该操作在 beforeFilter 中是允许的,但它仍然以某种方式妨碍它。

编辑:

AppController:

var $components = array('Auth', 'Session');

function beforeFilter()
  {
  $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');

  if (!$this->Auth->user())
    {
    $this->layout = 'login';
    }  
  }

控制器:

var $components = array('WkHtmlToPdf');

function beforeFilter() // I am logged in, so this shouldn't even be needed
  {
  $this->Auth->allow('pdf');
  }

function pdf()
  {
  $this->WkHtmlToPdf->createPdf();
  }

// this function is required for wkhtmltopdf to retrieve
// the viewdump once it's rendered
function getViewDump($fileName)
  {
  $this->WkHtmlToPdf->getViewDump($fileName);
  }

任何帮助将不胜感激, 保罗

I'm trying to use the WkHtmlToPdf Component, it seems like a nice tool when facing the problem of generating pdf files.

However - I can't get it to work with the Auth Component. The problem is that I always get the login page generated to pdf. I'm logged, the action is allowed in beforeFilter and it still somehow gets into the way of it.

EDIT:

AppController:

var $components = array('Auth', 'Session');

function beforeFilter()
  {
  $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');

  if (!$this->Auth->user())
    {
    $this->layout = 'login';
    }  
  }

Controller:

var $components = array('WkHtmlToPdf');

function beforeFilter() // I am logged in, so this shouldn't even be needed
  {
  $this->Auth->allow('pdf');
  }

function pdf()
  {
  $this->WkHtmlToPdf->createPdf();
  }

// this function is required for wkhtmltopdf to retrieve
// the viewdump once it's rendered
function getViewDump($fileName)
  {
  $this->WkHtmlToPdf->getViewDump($fileName);
  }

Any help would be greatly appreciated,
Paul

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

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

发布评论

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

评论(1

心病无药医 2024-10-27 07:37:00

事实证明,您必须允许 getViewDump 方法。它似乎不适用于 Auth,但允许每个人使用它并没有威胁,并且它有效。

控制器:

function beforeFilter()
    {
    parent::beforeFilter();
    $this->Auth->allow('getViewDump');
    }

It turns out, you have to allow the getViewDump method. It doesn't seem to work with Auth, but there is no threat with allowing it for everyone, and it works.

controller:

function beforeFilter()
    {
    parent::beforeFilter();
    $this->Auth->allow('getViewDump');
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文