开发者

How to handle different layouts in cakePHP

I have a cakePHP action that must return a CSV file in different formats according a parameter.

Which is the best way to write code for this?

-Should i return all data and creating different view based on that parameter? don't think so.

-Should开发者_运维百科 i pass the parameter to model and returning different fields from the model? i don't like the idea to insert a switch() in the model.

Other ideas? thanks !


in one of the cases i had to different outputs from data in my database(similar to yours but not csv) . crated a __Process() and passed type as a parameter.based on type it formatted the output and returned it back now my view just looped through the data and displayed it. I dont know if this answers your question

But from what u say different view is pretty okay.


This article in the CakePHP bakery describes how to return CSV files: http://bakery.cakephp.org/articles/jeroendenhaan/2010/04/23/exporting-data-to-csv-the-cakephp-way for CakePHP1.2. For version 2 there's a plugin: https://github.com/josegonzalez/cakephp-csvview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜