Newbie: Many data providers in one CListView


I would like to search data from several database tables, much more like this:

,but I don’t know how to display the search result. Could I use one CListView to display data that are taken from many data providers?

Also, how can I display the link of each record (from different data provider), so that when users click certain record, they are redirected to the ‘view’ page of the record?

Thank you for your consideration.

Or could we merge several data providers?

yes, you can.

you should read the guide carefully, as its easy to skip some important steps.

in particular check out the "relations" function of a model. this is where you setup table relations. you can use the "with" function to bring back data from related tables

You can pass multiple models to the same view, and use those models in the view

Check out the CHtml class for the hyperlink function

I’m sorry I think didn’t give a clear description for my problem.

What I mean is to search data (based on keyword) from several tables and display the result in one CListView.

These are the tables I have:

Apartment (name, address, price, etc.)

House (name, address, price, rent_price, etc.)

Land (name, address, price, area, etc.)

Those tables are unrelated each other. When users type a keyword in textfield, the application will search several fields of those tables at once and display the result (i.e. records containing data that matched the keyword).

How could I display the result in one CListView (since it seems I will need several data providers)? Or is there another way to do this?

Could you create a view in your database as a UNION query with these table. It sounds like their structure is close to make a SQL union possible. Then you access the view as if it were a table.

Hello, I had the same problem and I could resolve it with CArrayDataProvider. I have two classes: Empresa and Persona, both subclasses of Usuario, and I want to display a CListView with both Empresas and Personas.

        $criteria= new CDbCriteria(array(

		'condition'=> "estado=".Usuario::ESTADO_ACTIVO


	$personas= Persona::model()->findAll($criteria);

	$empresas= Empresa::model()->findAll($criteria);


	$dataProvider= new CArrayDataProvider(array_merge($personas, $empresas), array(

		'sort'=> array(

			'attributes'=> array(






    		'pagination'=> array(




I couldn’t find another solution for this issue, I think this should be a very common problem and people should have posted about it.

It is very difficult to get anyone who knows how to do this to actually help you do it, rather than just telling you to read the documentation that you’ve already read and don’t understand, because their examples are always cryptic and don’t show the context.

Very frustrating.