thinkphpÓÃʲôҪÁìŲÓÃÊÓͼ
thinkphpÊÇÒ»¸ö¿ªÔ´µÄphp¿ª·¢¿ò¼Ü£¬Ëü½ÓÄÉÃæÏò¹¤¾ßµÄ±à³ÌÍ·ÄÔ£¬ÊÇÒ»ÖÖÇáÁ¿¼¶¡¢¸ßЧ¡¢¿ì½ÝµÄphp¿ª·¢¿ò¼Ü¡£ÔÚthinkphpµÄ¿ª·¢ÖУ¬ÊÓͼÊǺÜÊÇÖ÷ÒªµÄÒ»²¿·Ö£¬ÓÃÓÚչʾÊý¾ÝºÍ·ºÆðÒ³ÃæЧ¹û¡£ÄÇô£¬ÔõÑùÔÚthinkphpÖÐŲÓÃÊÓͼÄØ£¿±¾ÎĽ«ÏêϸÏÈÈÝthinkphpÖÐÔõÑùŲÓÃÊÓͼ¡£
Ò»¡¢Ê²Ã´ÊÇÊÓͼ
ÔÚMVC¼Ü¹¹ÖУ¬ÊÓͼ²ãÖ÷ÒªÈÏÕæ·ºÆðÊý¾ÝºÍչʾҳÃæЧ¹û£¬ÊÇÕû¸öÓ¦ÓóÌÐòµÄ¡°Íâ¹Û¡±²¿·Ö£¬Óû§×îÖ±½Ó¸ÐÊܵ½µÄ²¿·Ö¡£ÊÓͼͨ³£°üÀ¨HTML±ê¼ÇºÍÏÔʾÊý¾ÝµÄ´úÂë¶Î¡£ÔÚThinkPHPÖУ¬ÊÓͼ±»´æ´¢ÔÚÏîÄ¿µÄviewĿ¼Ï£¬ÓÉÊÓͼÎļþºÍ½á¹¹Îļþ×é³É¡£ÔÚÒ³ÃæÏÔʾʱ£¬ÊÓͼÎļþµÄ¶ÔÓ¦½á¹¹Îļþ»á×Ô¶¯¼ÓÔØ¡£
¶þ¡¢Å²ÓÃÊÓͼµÄÒªÁì
1.ÔÚ¿ØÖÆÆ÷ÖÐŲÓÃÊÓͼ
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚThinkPHPÖУ¬¿ØÖÆÆ÷Êǵ÷ÀíºÍ´¦ÀíÓû§ÇëÇóµÄÖÐÐÄ£¬¿ØÖÆÆ÷¿ÉÒÔÔØÈëÄ£×ÓÀ´»ñÈ¡Êý¾Ý£¬ÔÙ½«Êý¾Ýת´ï¸øÊÓͼ¾ÙÐÐչʾ¡£Å²ÓÃÊÓͼµÄÒªÁìºÜÊǼòÆÓ£¬¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐʹÓÃ$this->fetch()ÒªÁì¡£
ÏÂÃæÊÇʾÀý´úÂ룺
public function index() { //´ÓÊý¾Ý¿âÖлñÈ¡Êý¾Ý $data = Db::name('article')->find(); //½«Êý¾Ýת´ï¸øÊÓͼ $this->assign('data', $data); //ŲÓÃÊÓͼ²¢¾ÙÐÐչʾ return $this->fetch(); }
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´³ö£¬$this->fetch()ÒªÌå»á×Ô¶¯Ñ°ÕҺͿØÖÆÆ÷¶ÔÓ¦µÄÊÓͼÎļþ£¬²¢¼ÓÔØÏìÓ¦µÄ½á¹¹ÎļþºÍÄ£°åÎļþ¡£
2.ÔÚÊÓͼÖÐŲÓÃÆäËûÊÓͼ
ÔÚThinkPHPÖУ¬ÊÓͼ֮¼ä¿ÉÒÔÏ໥ŲÓá£ÎÒÃÇ¿ÉÒÔÔÚÒ»¸öÊÓͼÎļþÖÐÒýÈëÁíÒ»¸öÊÓͼÎļþ¡£ÕâÖÖÒªÁìͨ³£ÓÃÓÚÒ³Ãæ½á¹¹µÄÉè¼Æ£¬½«¹«¹²µÄ²¿·Ö·ÅÔÚÒ»¸öÊÓͼÎļþÖУ¬ÆäËûÊÓͼÎļþÒýÓü´¿É¡£
ÏÂÃæÊÇʾÀý´úÂ룺
index.html£º
<!-- ÒýÈëÍ·²¿ --> {include file="header.html"} <!-- ÏÔʾÊý¾Ý --> {foreach $list as $vo} <li>{$vo.title}</li> <li>{$vo.content}</li> <li>{$vo.time}</li> {/foreach} <!-- ÒýÈëβ²¿ --> {include file="footer.html"}
µÇ¼ºó¸´ÖÆ
header.html£º
<div class="header"> <h1>ÍøÕ¾ÎÊÌâ</h1> <nav> <a href="/">Ê×Ò³</a> <a href="/about">¹ØÓÚ尊龙凯时人生就是搏</a> <a href="/contact">ÁªÏµ尊龙凯时人生就是搏</a> </nav> </div>
µÇ¼ºó¸´ÖÆ
footer.html£º
<div class="footer"> °æȨËùÓÐ?2019-2021 </div>
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´³ö£¬Ê¹ÓÃ{include}Óï¾ä¿ÉÒÔÒýÈëÆäËûµÄÊÓͼÎļþ¡£ÕâÑù¾ÍÄܹ»ÊµÏÖÒ³Ãæ½á¹¹ºÍ´úÂëµÄÖØÓã¬Ìá¸ß¿ª·¢Ð§ÂÊ¡£
Èý¡¢½áÓï
±¾ÎÄÏÈÈÝÁËÔÚThinkPHPÖÐŲÓÃÊÓͼµÄÒªÁ죬ÕÆÎÕÁËÕâЩҪÁì¿ÉÒÔÔ½·¢¸ßЧµØ¿ª·¢ÍøÕ¾¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÒªÆ¾Ö¤²î±ðµÄÐèÇóºÍÓªÒµÂß¼¾ÙÐÐÊÓͼÉè¼ÆºÍŲÓá£Í¬Ê±£¬ÕÆÎÕºÃÊÓͼµÄʹÓÃÒ²ÓÐÀûÓÚÒ³ÃæµÄÃÀ»¯ºÍÓû§ÌåÑéµÄÌáÉý¡£
ÒÔÉϾÍÊÇthinkphpÓÃʲôҪÁìŲÓÃÊÓͼµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡