Home >Backend Development >PHP Tutorial >Yii CDbCriteria 支持存储过程吗解决方案

Yii CDbCriteria 支持存储过程吗解决方案

WBOY
WBOYOriginal
2016-06-13 11:49:34820browse

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 />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn