Hi
[posting back to list]
On 15 Jul 2009, at 13:36, Sjaak Eenhuis wrote:
Hi there,
Render returns the content of the template, but the layout is always shown, even if I don't ouput anything from the controller.
Yes, you'd need to disable the layout in your controller:
$this->_helper->layout->disableLayout();
If I echo out the contents of the template, then these contents are correctly inserted into the layout.
But I want to capture the whole layout, including its content.
Ah, okay.
(This is just off the top of my head...)
//render the current action's view script via the ViewRenderer
$this->_helper->ViewRenderer->render();
//render the layout manually and capture the output
$output = $this->view->render(path/to/layout.phtml);
//disable the layout
$this->_helper->layout->disableLayout();
Try that.
It seems like templates are an output buffer layer (nested buffering), which isn't affected by disableOutputBuffering.
From:
carlton.gibson@noumenal.co.ukTo:
exceptione@hotmail.comSubject: Re: [fw-mvc] howto: capture action output, stream it as pdf
Date: Wed, 15 Jul 2009 13:10:31 +0100
Hi there,
Have you tried just assigning the result of the $view's render() call... [editing your code]
On 15 Jul 2009, at 13:04, Exception e wrote:
I've searched the web, the docs and everything and still couldn't find an
answer to a difficult question:
How can you capture the output of an action [to stream it as pdf with
dompdf]?
In a controller I have an action like
<?php
function getPdfAction() {
// use a different layout
$this->getHelper('layout')->setLayout('pdf-layout.phtml');
// I need to call render halfways, so no auto render
$this->getHelper('viewRenderer')->setNoRender();
//1 start capture content. although the docs says it returns a string,
there is no
// return in render()
// I also don't understand why I need to supply thisController explicitly,
but anyways..
// here:
$outputBuffer = $this->view->render('thisController/template.tpl');
// $outputBuffer should contain what you're after now.
$dompdf = new DOMPDF();
$dompdf->load_html(mb_convert_encoding($outputBuffer, 'html', 'UTF-8'));
$dompdf->render();
$dompdf->stream('hereisyourfile.pdf');
}
That should work no?
HTH
Carlton
How should I adapt this approach? Would it even be possible to capture the
output of an controller action in that very same action? Or do I need a
postDispatch?
Maybe it would be the nicest to have this html to pdf conversion as an
action helper, but is more important that I can deal with this simpler
problem.
I did not succeed with
$this->getFrontController()->setParam('disableOutputBuffering', true); in
preDispatch (which is ugly imho).
--
View this message in context:
http://www.nabble.com/howto%3A-capture-action-output%2C-stream-it-as-pdf-tp24496539p24496539.htmlSent from the Zend MVC mailing list archive at Nabble.com.
Plan je party en pimp je uitnodigingen met
Windows Live Events
没有评论:
发表评论