CArrayDataProvider with CGridView pagination Yii


Users Model:

public function getAllList(){
$sql = "SELECT * FROM users";
$cmd = Yii::app()->db->createCommand($sql);
return $cmd->queryAll();
}

Users Controller:

public function actionIndex(){
$model = Users::model()->getAllList();
$dataProvider = new ArrayDataProvider($model, array(
'keyField' => 'user_id',
'pagination' => array(
'pageSize' => 5,
),
)
);
$this->render('index',array(
'dataProvider' => $dataProvider,
)
);
}

Users Views:

index.php

$this->widget('zii.widgets.CListView', array(
'ajaxUpdate' => true,
'dataProvider' => $dataProvider,
'itemView' => '_view',   // refers to the partial view named '_carList'
'template' => '<h4><span>{summary}</span></h4>{items}{summary}{pager}',
'pagerCssClass' => 'pagination',
'summaryText' => '{start}-{end} of {count} Total Property ',
'pager' => array(
'header' => FALSE,
'firstPageLabel' => FALSE,
'lastPageLabel' => FALSE,
'nextPageLabel' => 'Next',
'prevPageLabel' => 'Previous',
'selectedPageCssClass' => 'active',
'maxButtonCount' => '5'
),
'beforeAjaxUpdate' => 'function(){
//todo before
}',
'afterAjaxUpdate' => 'function(){
//todo after
}',
));

_view.php

<p>
<?php echo $data['user_id']; ?>
<?php echo $data['user_name']; ?>
<?php echo $data['user_pass']; ?>
</p>

Share on Google Plus

About Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment