<?php namespace HomeController; use ThinkController; use HomefenyePage; class ZhuCeController extends Controller { //分页引用第三方类,注意命名空间,把分页类放到library下或是home模块下 function FenYe() { $molde = D("nation"); $total = $molde->count();//查询总数 //$page = new HomeFenYePage($total,1); $page = new HomeFenYePage($total,1); /*$sql = "select * from nation ".$page->limit;//原生态SQL语句 $attr = $molde->query($sql);*/ $attr = $molde->limit($page->limit)->select();//使用 $xinxi = $page->fpage(); //var_dump($attr); $this->assign("xinxi",$xinxi); $this->assign("nation",$attr); $this->display(); } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <table> <tr> <td>代号</td> <td>名称</td> </tr> <foreach name="nation" item="v"> <tr> <td><{$v.code}></td> <td><{$v.name}></td> </tr> </foreach> </table> <div><{$xinxi}></div> </body> </html>
注意命名空间
如果不使用原始SQL语句注意分页类中的修改