I am attempting to create a simple reports section of an app , i have created a reportscontroller and was wondering if there is any way of importing different models into it to render pdfs based on data from them , is this possible ?
I am attempting to create a simple reports section of an app , i have created a reportscontroller and was wondering if there is any way of importing different models into it to render pdfs based on data from them , is this possible ?
Iāve been dealing with the same need for the past weeks. One possibility is integrating Reportico PHP Report Generator into Yii but that is a project unto itself for which I donāt have the time right now.
What Iāve done is:
Create a ReportsController whose job is only to coordinate report processing using external actions.
Each report is a separate controller action outside of ReportsController - e.g. protected/controllers/actions/reports/Rpt001Action.php, etc. That way one can work on each report individually without messing up any other.
The parameters for each report are similarly collected into its own CForm model - e.g. protected/models/reports/Rpt001ParamsForm.php. Remember to import āapplication.models.reports.*ā in config/main.php.
Same structure for report views: protected/views/reports/ā¦
a) rpt001.php - starting view that renderpartials the report parameters view below
b.) _rpt001params.php - renderpartialed view that collects the reportās parameters in an CActiveForm using model Rpt001ParamsForms.php
c) rpt001results.php - CGridView/CListView/CDetailView/whatever view that displays the report results (which were processed in Rpt001Action)
d) _rpt001criteria.php - nice to have view which is renderpartialed into rpt001results.php so the report can display the criteria it was invoked with.
Going back to Rpt001Action.php it flows as follows:
instance report model & criteria: $model = new Rpt001ParamsForm; $criteria = new CDbCriteria;
if set process parameters (if not jump to step 6): if(isset($_POST[āRpt001ParamsFormā])){ā¦} and populate $criteria
instance dataprovider: $dataProvider = new CActiveDataProvider(āTableā, array(ācriteriaā=>$criteria,ā¦
render results: $this->controller->render(ārpt001resultsā, ādataProviderā=$dataProvider ā¦
Call Yii::app()->end(); to avoid a renderpartial loop
Upon first call (no $_POST content) render the original view rpt001.php.
If you want to have a PDF version of the report add the corresponding controllers/actions/reports/Rpt001pdfAction.php and views/reports/rpt001pdf.php with the logic to output to PDF or whatever. I usually open a new browser window/tab for this upon a button click.
Iām positive there are better ways of doing this, but it works, especially within the timeframe my project requires. Any suggestions are appreciated.
Thanks for the informative reply , iām just trying to get jasper reports working which may work for my situation , iāll let you know how i get on
No problem. I considered Jasper reports but would prefer a āpureā PHP solution so I donāt overload my affordable virtual server by having to support Java as well. Good luck.
Hi there
There is now a beta test module that integrates Reportico report designer into Yii ā¦ its available from the Reportico Web Site
To download or try out the module go to :-
http://www.reportico.org/yiidemo/reportico/index.php
Peter Deed