Zend PDF - 有没有一个很好的方法来完成MVC模式?

Given some user data.

Depending on the controller this data should be rendered either into a PDF or into a HTML file.

I really like the Zend way of the .phtml views combine HTML with very basic PHP.

Is there a similar approach for PDF and/or XLS that allows co-workers without strong programming background to change the PDF / XLS output?

HTML and PDF are different planets. Making output libraries that supports both media-types and their respective strengths is almost undoable.

The best solution I can think of is pandoc, http://johnmacfarlane.net/pandoc/

It's not a MVC of it's own, but used as library it may suit your needs.

regards //t

Well, not really for people without a strong programming background.

Basically, rendering a PDF or an Excel view is the same as rendering an HTML View, so you could put the generating code into .phtml files, generate the appropriate output and serve it with the appropriate content-type. It's just a different representation of the data in the Model then. You can utilize ZF's context switch helper for this.

But, HTML is markup and PHP was designed to be embedded in it, so this is cake to do - if you know the appropriate frontend technolgies, like HTML, CSS and JavaScript.

With Excel, you could use the Microsoft's SpreadsheetML and embed PHP into it the same way. This requires the co-worker to have some knowledge of that markup language and XML in general though.

I am not aware of any markup for PDF files, so this has to be generated through an API (likely Zend_PDF) completely. Well, you could probably invent something to define which data goes where in XML, but that would take some thought.

Edit since this is tagged Zend Framework, you might also want to consider using the LiveDocX service, which uses a template based approach and can create PDF and Excel.

In an MVC world, the PDF would just be another view. So if you had /controller/action/view.phtml then you should theoretically be able to have a URL like /controller/action/view.pdf.

It's similar to how you can choose your output format with an API such as, say Twitter's. Hitting http://api.twitter.com/version/statuses/public_timeline.json will return the result in JSON; hitting http://api.twitter.com/version/statuses/public_timeline.xml in XML; and so on.

Some of the PDF libraries also include the ability to import/display HTML in the PDF contents, several with advanced properties for handling various formats and unsupported tags. Most that I've used have had strict stipulations about which DTD you need to adhere to.

Use WKHTMLtoPDF to create a PDF from the HTML rendered view.