I just started using yii. My problem is the following.
My controller, passes an object (lets call it myObject) to a view. I would like to have a CHtml:Button on this page, which initiates an action (lets say myAction).
My object, i want to pass is a $dataProvider. My button supposed to export the result of the query to a PDF file. So the controller creates the query, passes the dataProvider to the, view. Here i have to create a button, wich generates the export. So it has to pass the $dataProvider, wich contains the results back to the controller!
Thus my object is not in the database, it is created by the controller.
Should i store the dataprovider in the database? I thougth about recreating the dataProvider again in the export action, but it is really a waste of resources, to do a query twice.
I know the feeling of "waste of resources" but as zaccaria pointed out: The Web is stateless by nature.
Question is: What is a greater waste of resources – Performing the query again -or- store and maintain the state (the query result) in the session (Yii::app()->user->setState/getState).
If you care about database queries storing the DataProvider won’t help because it does not contain the actual information but the query and settings to retrieve the specified pieces of information. You would need to always store the entire query result in the session and this would be a waste of resources, too. Why store the query result in the session just because some user might want to print it?
There are really no options, you have to repeat the query.
You don’t have to pass the whole dataprovider, just sort and filters. Usually if you do the export in pdf you want to export all pages.
Be careful: if you have a great number of records, don’t use ActiveRecord but direct access the database, as it would be too expensive in term of memory.