Using data providers
Data providers are used to encapsulate common data model operations such as sorting, pagination, and querying. They are used with grids and lists extensively. Because both widgets and providers are standardized, you can display the same data using different widgets and you can get data for a widget from various providers. Switching providers and widgets is relatively transparent.
Currently CActiveDataProvider, CArrayDataProvider, and CSqlDataProvider are implemented to get data from Active Record models, arrays, and SQL queries respectively. Let's try all these providers to fill a grid with data.
Getting ready
Create a new application using
yiic webappas described in the official guide.Download the Sakila database from http://dev.mysql.com/doc/index-other.html and execute the downloaded SQLs (first schema then data).
Configure the database connection in
protected/config/main.php.Use Gii to create a model for the
filmtable.
How to do it...
Let's start with a view for a grid...