Ôõô´î½¨thinkphp
thinkphpÊÇÒ»¿îºÜÊÇÊ¢ÐеÄphp¿ª·¢¿ò¼Ü¡£Ëü»ùÓÚmvc£¨Ä£×Ó-ÊÓͼ-¿ØÖÆÆ÷£©¼Ü¹¹£¬²¢ÓµÓÐÍêÉƵÄÊý¾Ý¿âorm£¨¹¤¾ß¹ØϵӳÉ䣩¹¦Ð§£¬Ê¹µÃ¿ª·¢ÕßÄܹ»¿ìËÙ¡¢¸ßЧµØÍê³ÉwebÓ¦ÓõĿª·¢¡£¿ÉÊÇ£¬¹ØÓÚ³õѧÕßÀ´Ëµ£¬thinkphpµÄ´î½¨¿ÉÄÜ»áÓöµ½Ò»Ð©ÄÑÌâ¡£±¾ÎĽ«»áÏêϸ½â˵ÔõÑù´î½¨thinkphp¡£
Ò»¡¢×°ÖúÍÉèÖÃÇéÐÎ
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃPHP¡¢ApacheÒÔ¼°MySQL»òÕßMariaDB¡£ÐÅÍи÷È˹ØÓÚÕâЩÈí¼þµÄ×°Öö¼ÒѾºÜÊÇÊìϤÁË¡£ËäÈ»ÓÐÐí¶àWAMP/LAMPµÄÌ××°Èí¼þ¿ÉÒÔÖ±½Ó×°ÖÃÕâЩÈí¼þ£¬¿ÉÊÇ×÷Ϊһ¸ö¿ª·¢Õߣ¬½¨Òé¸÷ÈË×ÔÁ¦×°ÖÃÕâЩÈí¼þ£¬ÕâÑùÓÐÀûÓÚÎÒÃǸüºÃµØÃ÷È·ÕâЩÈí¼þµÄʹÓúÍÉèÖá£
µÚÒ»²½£º×°ÖÃPHP
PHP¿ÉÒÔ´Ó¹ÙÍøÏÂÔØ×îа汾µÄ×°Öðü¾ÙÐÐ×°Öá£ÕâÀïÍƼöWindowsÏÂʹÓÃXAMPP»òÕßWAMP£¬Àû±ãÉèÖÃApacheºÍMySQLµÈ¡£
µÚ¶þ²½£º×°ÖÃApache
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ApacheÊÇÌìÏÂÉÏ×îÊ¢ÐеÄWebЧÀÍÆ÷Èí¼þÖ®Ò»¡£ÎÒÃÇ¿ÉÒÔ´ÓApache¹ÙÍøÏÂÔØ×îа汾µÄ×°Öðü¾ÙÐÐ×°Öá£
µÚÈý²½£º×°ÖÃÊý¾Ý¿â
MySQL»òÕßMariaDBÊÇ×î³£ÓõĹØϵÐÍÊý¾Ý¿âÖÎÀíϵͳ£¬¿ÉÒÔ´Ó¹ÙÍøÏÂÔØ×îа汾µÄ×°Öðü¾ÙÐÐ×°Öá£
µÚËIJ½£ºÉèÖÃÇéÐÎ
×îºó£¬ÎÒÃÇÐèÒªÉèÖÃÇéÐαäÁ¿¡£ÔÚWindows²Ù×÷ϵͳÖУ¬ÎÒÃÇ¿ÉÒÔ½«PHPºÍApacheµÄ¿ÉÖ´ÐÐÎļþËùÔÚ·¾¶¼ÓÈëPathÇéÐαäÁ¿ÖУ¬ÕâÑù¾Í¿ÉÒÔÔÚÏÂÁîÐÐÖÐÔËÐÐPHPºÍApacheÁË¡£ÁíÍ⣬ÎÒÃÇ»¹ÐèÒªÔÚApacheµÄÉèÖÃÎļþhttpd.confÖÐÉèÖÃPHPÆÊÎöÆ÷£¬ÈÃApacheÄܹ»Ê¶±ðPHPÎļþ¡£
¶þ¡¢ÏÂÔز¢×°ÖÃThinkPHP
Ò»µ©ÎÒÃÇ×°ÖúÃÁËPHP¡¢ApacheÒÔ¼°MySQL»òÕßMariaDB£¬¾Í¿ÉÒÔ×îÏÈÏÂÔز¢×°ÖÃThinkPHPÁË¡£
µÚÒ»²½£ºÏÂÔØThinkPHP
ÎÒÃÇ¿ÉÒÔ´Ó¹ÙÍøÏÂÔØThinkPHPµÄ×îа汾£¬²¢½âѹµ½ÎÒÃÇÖ¸¶¨µÄĿ¼Ï¡£
µÚ¶þ²½£ºÉèÖÃÊý¾Ý¿âÐÅÏ¢
ÎÒÃÇÐèÒªÔÚThinkPHPµÄÉèÖÃÎļþÖУ¨Î»ÓÚThinkPHP/Conf/config.phpÖУ©ÉèÖÃÊý¾Ý¿âÐÅÏ¢¡£ÎÒÃÇÐèÒªÉèÖÃÊý¾Ý¿âÀàÐÍ¡¢hostname¡¢database¡¢usernameÒÔ¼°passwordµÈÐÅÏ¢¡£
µÚÈý²½£ºÔËÐÐÈë¿ÚÎļþ
×îºó£¬ÎÒÃÇÐèÒªÔÚä¯ÀÀÆ÷ÖÐÔËÐÐThinkPHPµÄÈë¿ÚÎļþindex.php£¨Î»ÓÚThinkPHP/Library/Think/Template/driverÖУ©¡£ÎÒÃÇÊäÈëlocalhost/ThinkPHP/index.php£¬¼´¿É»á¼ûÎÒÃǴºÃµÄThinkPHPÓ¦Óá£
Èý¡¢Ê¹ÓÃThinkPHP
ÏÖÔÚÎÒÃÇÒѾÀֳɴºÃÁËThinkPHP£¬¿ÉÒÔ×îÏÈʹÓÿò¼Ü¾ÙÐпª·¢ÁË¡£½ÓÏÂÀ´£¬ÎÒ½«Îª¸÷ÈËÏÈÈÝһЩ»ù±¾µÄʹÓÃÒªÁì¡£
¿ØÖÆÆ÷
¿ØÖÆÆ÷ÊÇÒ»¸öThinkPHPÓ¦ÓÃÖÐ×î½¹µãµÄ²¿·ÖÖ®Ò»£¬ËüÈÏÕæÎüÊÕÓû§µÄÇëÇ󣬲¢¾ÙÐÐÏìÓ¦µÄ´¦Öóͷ£ºÍÊä³ö¡£
ÎÒÃÇ¿ÉÒÔÔÚThinkPHPÓ¦ÓõÄControllerĿ¼Ï½¨ÉèÒ»¸ö¿ØÖÆÆ÷£¬ºÃ±È˵½¨ÉèÒ»¸öÃûΪIndexControllerµÄ¿ØÖÆÆ÷¡£ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵¶à¸öÐж¯£¬ºÃ±È˵һ¸ö½Ð×öindexµÄÐж¯£¬´úÂëÈçÏ£º
class IndexController extends Controller {
public function index(){ $this->display(); }
µÇ¼ºó¸´ÖÆ
}
ÕâÀïµÄ$this->display()º¯ÊýÓÃÓÚäÖȾÊÓͼ¡£
Ä£×Ó
Ä£×ÓÖ÷ÒªÈÏÕæÓëÊý¾Ý¿â¾ÙÐн»»¥£¬»ñÈ¡ÏìÓ¦µÄÊý¾Ý¡£ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃORM¿ò¼Ü¾ÙÐпìËÙµÄÊý¾Ý¿â²Ù×÷¡£
ÎÒÃÇ¿ÉÒÔÔÚModelĿ¼Ï½¨ÉèÒ»¸öÄ£×Ó£¬ºÃ±È˵½¨ÉèÒ»¸öÃûΪUserModelµÄÄ£×Ó¡£ÔÚÄ£×ÓÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵¶à¸öÅÌÎÊÒªÁ죬ºÃ±È˵һ¸ö½Ð×ögetUserByIdµÄÅÌÎÊÒªÁ죬´úÂëÈçÏ£º
class UserModel extends Model {
public function getUserById($id){ $user = $this->where("id=" . $id)->find(); return $user; }
µÇ¼ºó¸´ÖÆ
}
ÕâÀïµÄ$this->where()ºÍ$this->find()º¯ÊýÓÃÓÚ¹¹½¨ÅÌÎÊÓï¾äÒÔ¼°ÅÌÎÊÊý¾Ý¡£
ÊÓͼ
ÊÓͼÈÏÕæ·ºÆðÊý¾Ý²¢ÓëÓû§¾ÙÐн»»¥¡£ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÊÓͼģ°åÀ´¹¹½¨×ðÁú¿Ê±Ò³Ãæ¡£
ÎÒÃÇ¿ÉÒÔÔÚViewĿ¼Ï½¨ÉèÒ»¸öÊÓͼ£¬ºÃ±È˵½¨ÉèÒ»¸öÃûΪindex.htmlµÄÊÓͼ¡£ÔÚÊÓͼÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃHTML¡¢CSSºÍJavaScriptµÈÊÖÒÕÀ´¹¹½¨×ðÁú¿Ê±Ò³Ãæ¡£
ÒÔÉϾÍÊÇÔõÑù´î½¨ThinkPHPºÍһЩ»ù±¾µÄʹÓÃÒªÁ졣ϣÍûÕâЩÐÅÏ¢Äܹ»¶Ô³õѧÕßÃÇÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇÔõô´î½¨thinkphpµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡