Maison >développement back-end >tutoriel php >Yii CDbCriteria 支持存储过程吗解决方案
Yii CDbCriteria 支持存储过程吗
如题
能附上片段代码更好
------解决方案--------------------
下面这是一种分页方法,或许对你有所帮助,你可先在sql里调用,执行query之后再绑定CDbCriteria
<br />$result = Yii::app()->db->createCommand($sql)->query();<br /> $recorderCount = $result->rowCount;<br /> $criteria = new CDbCriteria ();<br /> $pages = new CPagination($result->rowCount);<br /> $pages->pageSize =10;<br /> $pages->applyLimit($criteria);<br /> $result = Yii::app()->db->createCommand($sql . " LIMIT :offset,:limit");<br /> $result->bindValue(':offset', $pages->currentPage * $pages->pageSize);<br /> $result->bindValue(':limit', $pages->pageSize);<br /> $posts = $result->query();<br /> // render page.<br /> $this->controller->render('index', array(<br /> 'posts' => $posts,<br /> 'pages' => $pages,<br /> 'recorderCount' => $recorderCount<br /> ));<br />