phalcon框架内容列表示例
<?php
/**
* phalcon框架内容列表示例
*/
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\QueryBuilder as PaginatorQueryBuilder;
class ItvTopicController extends ControllerBase
{
/**
* 主题列表
*/
public function indexAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, "Topic", $_POST);
$this->persistent->parameters = $query->getParams(); //获取搜索参数
} else {
$numberPage = $this->request->getQuery("page", "int"); //取得页码
}
if ($numberPage ==null) {
$this->persistent->parameters = null; //如果页码为空,重置搜索参数
}
$parameters = $this->persistent->parameters;
if (!is_array($parameters)) {
$parameters = array();
}
if($this->request->getPost("topic")){ //搜索条件
$parameters["conditions"] .= " and topictype = 2 and status = 0"; //status:0正常,1删除
}else{
$parameters["conditions"] = "topictype = 2 and status = 0"; //status:0正常,1删除
}
//传递 QueryBuilder 数据
$builder = $this->modelsManager->createBuilder()
->columns('*')
->from('Topic') //数据库
->where($parameters['conditions'], $parameters['bind'])
->orderBy('id');
$paginator = new PaginatorQueryBuilder(
array(
"builder" => $builder,
"limit" => 20,
"page" => $numberPage
)
);
$this->view->page = $paginator->getPaginate(); //获取分页数据
}
}
?>
相关博文
phalcon框架开发内容列表分页示例