Is It Good Mvc Best Practice To Create A Dataprovider In A View?

Hi everyone.

I can’t seem to find a clear answer on this despite searching the forum and web all night.

Picture this. I have a view that loads {n} number of a model form in tabular fashion. For each form in the tabular view, I then have a grid view (or several grid views) that displays related data (HAS_MANY relations). At the moment, I create the data provider required for each partial grid view at the bottom of the parent form view file, then I call a render partial to bring the grid view in.

Can anyone tell me if it is appropriate to create/instantiate a CActiveDataProvider from within a view file? I’ve read that true MVC best practice is to never explicitly do database queries from within a view.

You’re right, it is best to not do database queries from views. Usually it is recommended that views do only output data. They can echo, iterate data and have conditionals.

If you think that sending these data from your controller isn’t the best approach, please take a lok at widgets.

I thought as much. Thanks for your response Rodrigo.

I’ll have a think about how I can load the data in the controller and pass it to the view.