thinkphpÔõÑù×ö·ÖÒ³
Ò»¡¢¿ØÖÆÆ÷ÖеĴúÂëʵÏÖ
ÔÚ¿ØÖÆÆ÷ÒªÁìÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýTP¿ò¼ÜÄÚÖõķÖÒ³Àà\think\paginator\driver\BootstrapÀ´Íê³ÉÊý¾Ý·ÖÒ³¹¦Ð§µÄʵÏÖ¡£ÎÒÃÇ¿ÉÒÔÏÈÅÌÎʳöÒª¾ÙÐзÖÒ³µÄÊý¾Ý£¬È»ºó½«ÅÌÎÊЧ¹ûת´ï¸ø·ÖÒ³À࣬ȻºóŲÓ÷ÖÒ³ÀàµÄrender()ÒªÁì¼´¿É¡£
ÏÂÃæÊÇÒ»¸ö¿ØÖÆÆ÷´úÂëµÄʾÀý£º
use \think\paginator\driver\Bootstrap;
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
public function index()
{
// ÅÌÎÊÎÄÕÂÁбíÊý¾Ý $articles = Db::name('article')->paginate(10); // ½«ÅÌÎÊЧ¹ûת´ï¸ø·ÖÒ³Àà $page = $articles->render(); // ½«·ÖÒ³ºóµÄÊý¾Ýת´ï¸øÄ£°å $this->assign('articles', $articles); $this->assign('page', $page); return $this->fetch('index');
µÇ¼ºó¸´ÖÆ
}
ÿҳÏÔʾÊý¾ÝÁ¿±»Ö¸¶¨Îª10£¬ÕâÊÇÔÚʾÀý´úÂëÖÐͨ¹ýpaginate()ÒªÁìÖеIJÎÊý¾ÙÐÐÉèÖõġ£$articles±äÁ¿Öд洢µÄÊÇÅÌÎʳöÀ´µÄÎÄÕÂÁбíÊý¾Ý£¬$page±äÁ¿Öд洢µÄ¾ÍÊÇ·ÖÒ³ºóµÄHTML´úÂë¡£
¶þ¡¢Ä£°åÖеĴúÂëʵÏÖ
ÔÚÄ£°åÖУ¬ÎÒÃÇ¿ÉÒÔ̫ͨ¹ýÒ³ÀàµÄrender()ÒªÁì·µ»Ø·ÖÒ³HTML´úÂ룬ȻºóÔÚÒ³ÃæÉÏäÖȾ·ÖÒ³µ¼º½¡£
ÏÂÃæÊÇÒ»¸öÄ£°å´úÂëµÄʾÀý£º
{volist name="articles" id="article"} <li>{$article.title}</li> {/volist}
µÇ¼ºó¸´ÖÆ
{$page}
µÇ¼ºó¸´ÖÆ
ÎÒÃÇʹÓÃÁËTP¿ò¼ÜµÄvolist±êÇ©ÔÚ´úÂëÖÐÑ»·Êä³öÁËÎÄÕÂÁÐ±í¡£ÎÒÃÇʹÓÃ{$page}ÔÚÑ»·¿¢ÊºóÊä³ö·ÖÒ³µ¼º½µÄHTML´úÂë¡£
ÒÔÉϾÍÊÇthinkphpÔõÑù×ö·ÖÒ³µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡