在模塊控制器Controller文件夾裏建立一個 FenyeController.class.php控制器
<?php namespace Admin\Controller; use Think\Controller class FenyeController extends Controller{ public function xianshi(){ $c = D("chinastates"); $shuliang = $c->count();//求出總數量 $page = new \Admin\page\Page($shuliang,15);//分頁類對象 //var_dump($page); $xinxi = $page->fpage();//調出fpage()分頁信息 $attr = $c->limit($page->limit)->select();//調出分頁裏的limit()方法, $this->assign("shuju",$attr); $this->assign("xinxi",$xinxi); $this->show(); //var_dump($this->view); }
<!--*********************************************分割線 上面是實現分頁 下面是函數測試取字符串長度***********************************************************************--> public function test(){ $str = "limit方法也能夠用於寫操做,例如更新知足要求的3條數據: $User = M('User');$User->where('score=100')->limit(3)->save(array('level'=>'A'));分頁查詢 用於文章分頁查詢是limit方法比較經常使用的場合,例如: $Article = M('Article');$Article->limit('10,25')->select();表示查詢文章數據,從第10行開始的25條數據(可能還取決於where條件和order排序的影響 這個暫且不提)。 "; $m = A("Fenye"); echo $m->ChangDu($str); } public function ChangDu($str){//調test方法裏的另外一個方法ChangDu return strlen($str);//strlen()方法取長度 } //方法二 public function test1(){ $str = " limit方法也能夠用於寫操做,例如更新知足要求的3條數據: $User = M('User');$User->where('score=100')->limit(3)->save(array('level'=>'A'));分頁查詢 在教學中你咋不發 用於文章分頁查詢是limit方法比較經常使用的場合,例如: $Article = M('Article');$Article->limit('10,25')->select();表示查詢文章數據,從第10行開始的25條數據(可能還取決於where條件和order排序的影響 這個暫且不提)。 "; echo ChangDu($str);//在Common文件夾裏添加有關thinkphp框架的函數在網上找的或者在其餘地方看到的只要thinkphp框架能調用這個函數均可以!將函數名做爲文件名 好比functions也是一個函數 就將這個函數做爲文件名,functions.php }
}
functions函數 調用方法二test1方法裏的另外一個方法 一樣能夠取長度php
<!--**************************************************************************分割符 下面是顯示的實現分頁信息****************************************************-->
在模塊視圖(顯示頁面)View文件夾裏先建立好Fenye文件夾(表明的是Fenye控制器),裏面再建立xianshi.html頁面(表明的是你自定義的方法)html
<html> <head> <meta content="text/html; charset=utf-8" /> </head> <body> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>代號</td> <td>名稱</td> <td>父級代號</td> </tr> <foreach name="shuju" item="v" > <tr> <td>{$v.areacode}</td> <td>{$v.areaname}</td> <td>{$v.parentareacode}</td> </tr> </foreach> </table> <div>{$xinxi}</div><!--顯示分頁信息--> </body> </html>