thinkphpÎÞÏÞ¼«·ÖÀàµÄÒªÁì
Ëæ×Å»¥ÁªÍøÐÐÒµµÄÒ»Ö±Éú³¤£¬ÔÚÍøÕ¾¿ª·¢ÖÐʹÓúǫ́ÖÎÀíϵͳÒѳÉΪ±ØÐèÆ·¡£È»¶ø£¬ÍøÕ¾ÔÚÖÎÀíÀú³ÌÖУ¬Ëæ×ÅÊý¾ÝµÄÒ»Ö±»ýÀÛ£¬·ÖÀàÔ½À´Ô½¶à£¬Ê¹µÃÔÚÒ³ÃæÉÏչʾʱ£¬Ðèƾ֤·ÖÀà¾ÙÐйéÄÉÕûÀí¡£ÔÆÔÆÒ»À´£¬±ãÐèҪʹÓõ½·ÖÀàÖÎÀíµÄÒªÁì¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphp¿ò¼ÜµÄÎÞÏÞ¼«·ÖÀàÒªÁ죬À´ÊµÏÖÍøÕ¾·ÖÀàµÄÖÎÀí¡£
ʲôÊÇthinkphp¿ò¼Ü£¿
thinkphpÊÇÒ»¿îÓÅÒìµÄ¿ò¼ÜÊÖÒÕ£¬¼ÌÐøÁ˹ŰåÍøÕ¾¿ª·¢¿ò¼ÜµÄÓŵ㣬ͬʱÈÚºÏÁËÄ¿½ñÖ÷Á÷µÄÊÖÒÕÒªÁì¡£thinkphp¿ò¼Ü²»µ«½ö¾ß±¸¸ßЧºÍÀû±ã£¬»¹¾ßÓÐÓÅÒìµÄÀ©Õ¹ÐԺͼæÈÝÐÔ¡£ÔÚʹÓÃthinkphp¿ò¼Üʱ£¬ÎÒÃÇ¿ÉÒÔ×èֹͨÀýµÄ´úÂëÖظ´£¬Ìá¸ß´úÂëÔËÐÐЧÂÊ¡£
ʲôÊÇÎÞÏÞ¼«·ÖÀࣿ
ÎÞÏÞ¼«·ÖÀàÊÇÖ¸·ÖÀàÊ÷ÐνṹµÄÎÞÏÞÀ©Õ¹£¬²»ÏÞ²ãÊý¡¢²»ÏÞÊýÄ¿¡£Óë¹Å°åµÄÀο¿·ÖÀà·½·¨Ïà±È£¬ÎÞÏÞ¼«·ÖÀà·ºÆð³ö¸üÇ¿µÄÎÞаÐÔºÍÊý¾ÝÕûÀíµÄ±ã½ÝÐÔ¡£ÔÚÍøÕ¾ÖÐʹÓÃÎÞÏÞ¼«·ÖÀ࣬¿ÉÒÔƾ֤ÐèÒªÔ½·¢Àû±ãµØ¾ÙÐÐÌí¼Ó¡¢Ð޸ĺÍɾ³ý¡£
thinkphp¿ò¼ÜÔõÑùʵÏÖÎÞÏÞ¼«·ÖÀࣿ
thinkphp¿ò¼Üͨ¹ýʹÓõݹéµÄ·½·¨ÊµÏÖÎÞÏÞ¼«·ÖÀà¡£µÝ¹éÊÇÒ»ÖÖƾ֤Ŀ½ñÇéÐÎÖظ´Å²ÓÃ×ÔÉíµÄÒªÁì¡£ÔÚÎÞÏÞ¼«·ÖÀàÖУ¬Ã¿¸ö·ÖÀà½áµã¶¼ÓÐ×Ô¼ºµÄidÓ븸½Úµãpid¡£Í¨¹ý¶ÔpidµÄÒ»Ö±µÝ¹é£¬ÎÒÃÇ¿ÉÒÔÇáËɵػñÈ¡ËùÐèµÄ·ÖÀàÐÅÏ¢¡£
´úÂëʵÏÖ
(1) ½¨ÉèÊý¾Ý¿â²¢½¨Éè·ÖÀà±í
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¼Ù¶¨ÓÐÒ»¸öblogÍøÕ¾£¬ÐèÒª¶ÔÎÄÕÂƾ֤±êÇ©¾ÙÐзÖÀàÖÎÀí¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸ö·ÖÀà±í£¬±íÖаüÀ¨ÒÔÏÂ×ֶΣºid¡¢name¡¢pid¡£ÆäÖУ¬idΪ·ÖÀàµÄΨһ±êʶ£¬nameΪ·ÖÀàµÄÃû³Æ£¬pidΪ·ÖÀàµÄ¸¸½Úµãid¡£
(2) ÔÚControllerÖÐÌí¼Ó·ÖÀàÏÔʾҪÁì
public function category() {
//»ñÈ¡·ÖÀàÊý¾Ý
$categories = $this->getCategories();
$this->assign(‘categories’, $categories);
return $this->fetch();
}
(3) ÔÚModelÖÐÌí¼Ó»ñÈ¡·ÖÀàÒªÁì
public function getCategories($pid=0) {
$result = $this->where(‘pid’, $pid)->select();
$categories = array();
foreach ($result as $category) {
$category['sub'] = $this->getCategories($category->id); $categories[] = $category;
µÇ¼ºó¸´ÖÆ
}
return $categories;
}
(4) ÔÚViewÖÐչʾ·ÖÀàÊý¾Ý
{volist name=”categories” id=”category”}
{$category.name}
{if $category.sub} <ul> {volist name="category.sub" id="sub"} <li>{$sub.name}</li> {/volist} </ul> {/if}
µÇ¼ºó¸´ÖÆ
{/volist}
ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃǾͿÉÒÔʵÏÖthinkphp¿ò¼ÜµÄÎÞÏÞ¼«·ÖÀàÒªÁ죬²¢Í¨¹ý¶ÔpidµÄµÝ¹éÅÌÎÊ£¬½«·ÖÀàÐÅÏ¢ÒÔÊ÷ÐνṹÔÚÒ³ÃæÉϾÙÐÐÏÔʾ¡£
×ܽá
ͨ¹ý¶Ô±¾ÎĵÄÔĶÁ£¬ÎÒÃDz»µ«¿ÉÒÔÕÆÎÕthinkphp¿ò¼ÜµÄÎÞÏÞ¼«·ÖÀàÒªÁ죬»¹¿ÉÒÔÏàʶµÝ¹éÔÚ·ÖÀàÖÎÀíÖеÄÓ¦Óá£ÏÖÔÚ£¬·ÖÀàÖÎÀíÒѳÉΪºǫ́ÖÎÀíϵͳµÄ±Ø±¸¹¦Ð§Ö®Ò»¡£Òò´Ë£¬Ñ§»áthinkphp¿ò¼ÜµÄÎÞÏÞ¼«·ÖÀàÒªÁ죬¿ÉÒÔÌá¸ßÎÒÃǵĿª·¢Ð§Âʲ¢Ê¹ÎÒÃǵÄÍøÕ¾Ô½·¢¹æ·¶ºÍÒ×Óá£
ÒÔÉϾÍÊÇthinkphpÎÞÏÞ¼«·ÖÀàµÄÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡