php - Use CPagination with createCommand function in Yii framework -
php - Use CPagination with createCommand function in Yii framework -
i trying utilize cpagination.the illustration shown here http://www.yiiframework.com/doc/api/1.1/cpagination using criteria. using stored procedure selecting data. database used postgresql. calling stored procedure using create command function.
$command = yii::app()->db->createcommand("select sp_images_select(:project_id,:milestone_id);"); $command->bindparam(":project_id",$this->project_id,pdo::param_str); $command->bindparam(":milestone_id",$this->milestone_id,pdo::param_str); $command->queryall();
how can utilize cpagination result set of command. using ajax display image gallery explained here http://www.yiiframework.com/wiki/49/update-content-in-ajax-with-renderpartial/
please help.
thanks in advance.
this can done if can apply limit
(maximum records retrieve) , offset
(from record start) in way stored procedure.
let's go step step through illustration , analyze needed
your yii controller images
function actionindex(){ //not needed, apply criteria in stored procedure //arguments of stored procedure. //$criteria=new cdbcriteria(); // in way have able determine how many records // returned stored procedure when no limits set // (your challenge). $count= ..; // challenge here // create pagination object $pages=new cpagination($count); // results per page, configure maximum number of rows // displayed (the limit). $pages->pagesize=10; // set page on. either starting page (0) or page // when action called linker (clicking on button // go certanin page). linker send page using get. // pages 0 based have decrease received page // 1. $pages->currentpage = (isset($_get['page']) ? $_get['page']-1 : 0) // can not utilize this. method applies criteria plain // vanilla query (not stored procedure) , extends query // limit , offset. //$pages->applylimit($criteria); // instead, retrieve limit , offset pagination // object , pass stored procdure. f.i. $command->bindparam(":limit",$pages->limit,pdo::param_int); $command->bindparam(":offset",$pages->offset,pdo::param_int); // the images stored procedure. $images=$command->queryall(); // display images using view $this->render('index', array( 'images' => $images, 'pages' => $pages )); }
so, have if want utilize aforementioned approach:
find out if stored procedure supportslimit
, offset
if so, extend arguments of stored pocedure receive limit
, offset
, apply it find way determine number of records stored procedure result in when limit
, offset
not set. needed pagination object can calculate offset
based on current page hope on track...
php postgresql yii
Comments
Post a Comment