opencart3前台分页类的使用思路

//获得文章个数。
			$product_total=$this->model_catalog_information2category->getTotalInformations("where category_id in (".$category_id.")");//1,2,3,4,5格式,方便后期扩展
			//echo $product_total;

			
//获得当前多少页
			if (isset($this->request->get['page'])) {
				$page = (int)$this->request->get['page'];
			} else {
				$page = 1;
			}
//定义一页显示记录数
			$limit=2;
//拼装url其他参数,比如文章的分类,这些是分页和搜索的条件。
			$url = '';
			if (isset($this->request->get['category_id'])) {
				$url .= '&category_id=' . $this->request->get['category_id'];
			}
//实例化分页类
			//测试分页
			$pagination = new Pagination();
			$pagination->total = $product_total;
			$pagination->page = $page;
			$pagination->limit = $limit;
			$pagination->url = $this->url->link('information2/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
//这个是在视图中调用的,直接输出分页样式和对应的分页链接。
			$data['pagination'] = $pagination->render();

			$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));

//内容还是要输出显示的。	
			$start=($page-1)*$limit;
			//得到文章列表
			$arrlist=$this->model_catalog_information2category->getInformations(array("start"=>$start,"limit"=>$limit)," and i.category_id=".$category_id);
			//print_r($arrlist);
			$data['arrlist']=$arrlist;
//渲染模板
			$this->response->setOutput($this->load->view('information2/category', $data));

视图中:分页使用格式参考:

{% for v in arrlist %}
{{v.title}}<br/>
{% endfor %}
{{pagination}}{{results}}


关注公众号,了解更多it技术(it问答网

发表评论

电子邮件地址不会被公开。