I am a beginner in Yii. I am using the views/myModel/index.php page to list all records in the MySQL table. By default the number of records displayed per page is 10. How can I change it ?
First of all model folder should not contain index.php. this folder contains all classes related with your database tables(CActiveRecords) and other models.
for increasing number of records per page you can set pagesize of pagination in CGridView or CListView.
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Invoice',
array(
'criteria'=>array(
'with'=>array('client'),
'condition'=>'businessId='. Yii::app()->userInfo->business,
),
'pagination'=>array('pageSize'=>20,),
)
);
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
You can also do something like this in your code:
$criteria = new CDbCriteria;
$criteria->condition = "...";
$criteria->params = array();
$criteria->limit = 20;
$criteria->offset = 0;
$records = YourModel::model()->findAll($criteria);
Where limit is the number of records to show per page and offset is where the record number start, which you can use as your page number.