General Mvc Question - Complex Sql Queries

I’m working on my first project in Yii and found the framework very efficient. I finished the data entry interface of the application where I found AR very useful, but now I would like to create some reports where I need to use complex SQL queries instead of AR and its relations. [size=2]In some cases I need to query data from 5-6 tables at the same time and iterate through its results to create other queries since my view is a quite difficult matrix.[/size]

[size=2]

[/size]

[size=2]I know that based on the MVC pattern it’s recommended to keep SQL queries in the model, but what if I need to iterate through its results and put something to the screen based on that and then prepare another query based on its result and so on. Where should I put my SQL queries then? Do I need to prepare/produce all results in my model and pass it to my view? How can I pass all results to my view? Do I need to use array or SQL data providers? What is the common practice in such a case?[/size]

[size=2]

[/size]

[size=2]If you can recommend any reading on this topic that would be also fine.[/size]

[size=2]

[/size]

[size=2]Thanks in advance,[/size]

This can help you:

DAO vs Active Record

Where put DAO

The way I have worked and which have obtained better results is to put all DAO-code inside a DAO folder (within the protected folder) and pass the results within a ArrayDataProvider (controller) with the data obtained from the queries.

It is just an idea.

;)

Thanks Daniel! I’ll take a look at these.