0
votes

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

1
Can you post your app controller and the controller where the component is used? Just the relevant bits will do - JohnP
Shouldn't you be calling parent::beforFilter() in your controller? - JohnP
Well, yeah - but it doesn't change anything, the beforeFilter in Controller shouldn't be needed, since I'm logged in. - pawelmysior

1 Answers

0
votes

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');
    }