model view controller - Using html2pdf to generate a report using

Using html2pdf to generate a report using php and mvc pattern Ask Question

I have setup an application that somehow uses a front-controller. And I came across a library called html2pdf. This library converts html to pdf. Like this:

Exemple d'utilisation

Ceci est un exemple d'utilisation de HTML2PDF.
"; require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php'); $html2pdf = new HTML2PDF('P','A4','fr'); $html2pdf->WriteHTML($content); $html2pdf->Output('exemple.pdf'); ?>

As you can see, the libary can transform that html to a pdf. It can even read an html file and convert it to pdf. Okay here is the setup of my controller. class TestController extends Controller { private $template; public function __construct(View $view = null) { parent::__construct($view); $this->template = 'test'; // replace this } public function index() { $this->view->data['someinfo'] = 'information about me'; $this->view->render($this->template); } }

My idea is, instead of rendering the template out, and replacing of php.


variable by

information about me

because I used the



I could just replace the variables, and then save the output as html, so that I could use html2pdf to convert it to pdf? Are there already implementation of this? Or are there more efficient solutions rather than creating and html file and converting it? Thank you. php model-view-controller pdf-generation fpdf asked Apr 1 '13 at 16:03

Joey Hipolito 1,175




1 Answer

In the ZendFramework MVC you might do something like this in the controller: function toPdfAction() { // I need a different layout $this->getHelper('layout')->setLayout('pdf-layout'); $this->_helper->layout->disableLayout(); // we need to do renderering ourselves. $this->getHelper('viewRenderer')->setNoRender(); /* @var $layout Zend_Layout */ $layout = $this->_helper->layout->getLayoutInstance(); $layout->assign('content', $this->view->render('mycontroller/myaction.tpl')); $output = $layout->render(); // now we still need to ensure that the rendering is not sent to the browser $this->getResponse()->clearBody(); // now do something with $ouput like convert it to PDF and stream it back }

However, the answer is going to MVC implementation specific. If you are not using Zend, that likely won't work for you. What MVC Framework are you using? answered Apr 1 '13 at 16:15

bubba 3,408



I created a mini-mvc framework, yeah I think prolly that won't be applicable to my framework, but I can take a look on how zend does it. – Joey Hipolito Apr 1 '13 at 16:17

Well .. putting something like this in a controller would be against the basic principles of MVC and MVC-inspired design patterns. Just because Zend does it this way, does not mean that it is a good practice. – tereško Apr 1 '13 at 16:19

@tereško, yeah, it'll surely break the 'good practice'. I wonder how can I do it. – Joey Hipolito Apr 1 '13 at 16:23

This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.


model view controller - Using html2pdf to generate a report using

Using html2pdf to generate a report using php and mvc pattern Ask Question I have setup an application that somehow uses a front-controller. And I ca...

91KB Sizes 5 Downloads 0 Views

Recommend Documents

Model View Controller
PHP & MVC. The model view controller pattern is the most used pattern for today's world web applications. It has been us

Model View Controller - Wikiwand
Model View Controller ist ein Muster zur Trennung von Software in die drei Komponenten Datenmodell , Präsentation und P

The Model-View-Controller architectural pattern (MVC) divides an interactive application into three components. .... In

Codeigniter 3 - Generate PDF from view using dompdf library with
Feb 26, 2017 - codeigniter pdf generator library, codeigniter pdf generator tutorial, how to generate pdf using dompdf i

Using yii framework generate data report Jobs, Employment | Freelancer
Search for jobs related to Using yii framework generate data report or hire on the world's largest freelancing marketpla

Understanding Model-View-Controller - Coding Horror
May 5, 2008 - But the first step to harnessing MVC is to understand why it works, both on the web, and also within your

Model View Controller — Википедиа нэвтэрхий толь
ColdFusion on Wheels A convention over configuration framework similar to Ruby on Rails. ... Mach-II A framework that fo

Understanding Model-View-Controller - 1.3 - CakePHP cookbook
Programming using MVC separates your application into three main parts: The Model ... Figure: 1 shows an example of a ba

Model View Controller(MVC) In PHP Tutorial
Aug 10, 2009 - Despite the fact that the MVC pattern is very popular in PHP, is hard to find a proper tutorial accompani

according to the source to which their zero is attributable and make sta- tistical inferences about the properties of th