Hello,
I am currently in progress fairly large project in which I use cache due to the large number of queries and data. The question arises of how to set up something pagination in Yii using CDbCache
I can give you an currently example of the action of Controller:
public function actionIndex()
{
$streams_cached = Yii::app()->cache->get('streams');
if($streams_cached === false) {
$streams = PsStreamsMainModel::model()->findAll();
if($streams !== null) {
foreach($streams as $stream) {
$list_stream[] = $stream['channel_name'];
}
$curl = Yii::app()->curl->get('//api.*****/kraken/streams?channel='.strtolower(implode(',', $list_stream)), array());
$array_with_streams = json_decode($curl, true);
}
//cache it
Yii::app()->cache->set('streams', $array_with_streams, 300);
}
$streams_cached = Yii::app()->cache->get('streams');
$this->render('index', array('streams' => $streams_cached));
}
Perhaps a brief description of the variables:
$streams_cached
returns the array of data (in the middle of several records marked sequentially array[1], array[2]).
How to create pagination now walking in the spirit of CPagination:
$criteria=new CDbCriteria();
$count=Article::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Article::model()->findAll($criteria);
$this->render('index', array(
'models' => $models,
'pages' => $pages
));
Please help as well have a lot of trouble how to connect it with cache.
Regards