ÔõôÔÚµçÄÔÔËÐÐthinkphp
ÔÚÏÖÔÚ»¥ÁªÍøµÄʱ´ú£¬ÍøÕ¾µÄ¿ª·¢ÒѾ³ÉΪÁËÒ»¸ö·Ç³£»ðÈȵÄÐÐÒµ¡£¿ª·¢Ò»¸öÍêÕûµÄÍøÕ¾ÐèÒªºÜÊǶàµÄÊÂÇéºÍÊÖÒÕÖ§³Ö£¬ÔÚÕâЩÊÖÒÕÖУ¬Ò»¸öºÜÊÇÖ÷ÒªµÄÊÖÒÕ¾ÍÊÇphp¿ò¼Ü£¬ÆäÖÐthinkphpÊÇ×î³£ÓõÄÒ»¸ö¡£
ThinkPHPÊÇÒ»¸ö¿ªÔ´µÄPHP¿ò¼Ü£¬Æä·ºÆðÖ¼ÔÚ×ÊÖú¿ª·¢Õß¹¹½¨¸ßЧ¡¢¿Éά»¤¡¢ÓÅÑÅ¡¢¾«Á·µÄWebÓ¦ÓóÌÐò¡£ThinkPHP¿ò¼Ü¼¯³ÉÁË´ó×ÚµÄÄ£¿éºÍ¹¤¾ß£¬¿ÉÒÔ¿ìËÙ¿ª·¢³ö¸ßÖÊÁ¿µÄWebÓ¦ÓóÌÐò¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚµçÄÔÉÏÔËÐÐThinkPHP¡£
Ò»¡¢ÇéÐÎÉèÖÃ
ÔÚÔËÐÐThinkPHP֮ǰ£¬ÐèÒªÖª×ãÒÔϵĿª·¢ÇéÐΣº
PHP ÇéÐΣºPHP 5.6+£¬ÍƼöʹÓà PHP7.2+£¬ÏêϸµÄ×°ÖÃÒªÁì¿ÉÒÔ²ÎÕÕPHP¹ÙÍø¸ø³öµÄ˵Ã÷¾ÙÐÐ×°Öá£
MySQL Êý¾Ý¿â£ºÍƼöʹÓà MySqli »òÕß PDO Êý¾Ý¿âÇý¶¯£¬Ò²¿ÉÒÔʹÓÃÆäËûµÄÊý¾Ý¿â¡£
ЧÀÍÆ÷ÇéÐΣºApache »òÕß Nginx£¬ÍƼöʹÓà Apache¡£
Composer ¹¤¾ß£º×°ÖÃComposer¿ÉÒÔʹÓÃPHPÒÀÀµÖÎÀíÆ÷£¬½«¿ò¼ÜËùÒÀÀµµÄÍⲿ¿â£¬Í¨¹ýÒ»¸öÉèÖÃÎļþ¾ÙÐÐÒÀÀµÖÎÀí¡£ÏêϸµÄ×°ÖÃÒªÁì¿ÉÒÔ²ÎÕÕTinkPHP¹ÙÍøÉϵÄ˵Ã÷¾ÙÐÐ×°Öá£
¶þ¡¢ÏÂÔØThinkPHP¿ò¼Ü
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚÇéÐÎÉèÖÃÍê³Éºó£¬¾Í¿ÉÒÔ×îÏÈÏÂÔØThinkPHP¿ò¼ÜÁË¡£¿ÉÒÔÔÚThinkPHP¹ÙÍøÉÏÏÂÔص½×îаæµÄ¿ò¼Ü´úÂ룬ͬʱҲ¿ÉÒÔ´ÓGithubÏÂÔØThinkPHPÏîÄ¿Ô´´úÂë¡£
ÏÂÔØÍê³Éºó£¬½«¿ò¼ÜÎļþ½âѹºó°²Åŵ½Ð§ÀÍÆ÷µÄÍøÕ¾¸ùĿ¼Ï¡£
Èý¡¢ÉèÖÃÓ¦ÓóÌÐò
ÔÚÉèÖÃÓ¦ÓóÌÐò֮ǰ£¬ÐèÒªÏÈÉèÖÃÒ»¸öÐéÄâÖ÷»úÀ´»á¼ûThinkPHPµÄÓ¦ÓóÌÐò¡£ÔÚApacheÖУ¬¿ÉÒÔ±à¼httpd.conf»òÕßÌí¼ÓÒ»¸öרÃŵÄÐéÄâÖ÷»úÉèÖÃÎļþ¡£
ÔÚhttpd.confÖÐÌí¼ÓÒÔÏ´úÂ룺
<VirtualHost *:80> ServerName test.com #ÉèÖÃÓòÃû DocumentRoot "/usr/local/var/www/test" #Ö¸ÏòÓ¦ÓóÌÐòµÄĿ¼ <Directory "/usr/local/var/www/test"> AllowOverride All #ÔÊÐí.htaccess Require all granted </Directory> </VirtualHost>
µÇ¼ºó¸´ÖÆ
Íê³ÉÐéÄâÖ÷»úµÄÉèÖúó£¬×îÏÈÉèÖÃÓ¦ÓóÌÐò¡£½«½âѹ³öÀ´µÄ¿ò¼ÜÎļþ¸´ÖƵ½ÍøÕ¾¸ùĿ¼Ï£¬ÉèÖÃconfig.phpÎļþÖеÄÊý¾Ý¿âÅþÁ¬ÐÅÏ¢£¬¾Í¿ÉÒÔ×îÏÈ»á¼ûÓ¦ÓóÌÐòÁË¡£
ËÄ¡¢Ê¹ÓÃThinkPHP
ʹÓÃThinkPHP¾ÙÐпª·¢¿ÉÒÔ¿ìËÙ¹¹½¨³ö¸ßÖÊÁ¿µÄWebÓ¦ÓóÌÐò£¬Í¬Ê±Ò²ÌṩÁËÇ¿Ê¢µÄORM£¬Ä£°åÒýÇ滺ºÍ´æµÈ¹¤¾ß¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£º
½¨Éè¿ØÖÆÆ÷
½¨ÉèÒ»¸öÃûΪIndex¿ØÖÆÆ÷£¬ÐèÒªÔÚÓ¦ÓóÌÐòĿ¼ÏµÄIndexĿ¼Öн¨ÉèIndexController.phpÎļþ¡£´úÂëÈçÏ£º
<?php namespace appindexcontroller; class IndexController { public function index() { return 'Hello ThinkPHP£¡'; } } ?>
µÇ¼ºó¸´ÖÆ
½¨ÉèÄ£°å
ÔÚÓ¦ÓóÌÐòµÄ¸ùĿ¼Ï½¨Éèindex.htmlÎļþ£¬´úÂëÈçÏ£º
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>½Ó´ýÀ´µ½ThinkPHP£º{$title}</title> </head> <body> <h1>{$content}</h1> </body> </html>
µÇ¼ºó¸´ÖÆ
3.Ð޸ķÓÉ
ÔÚÓ¦ÓóÌÐò¸ùĿ¼ÏµÄroute.phpÎļþÖÐÌí¼Ó·ÓɹæÔò£¬´úÂëÈçÏ£º
<?php use thinkRoute; Route::get('hello/:name', 'index/index/hello'); //Ìí¼Ó·ÓɹæÔò ?>
µÇ¼ºó¸´ÖÆ
»á¼ûÓ¦ÓóÌÐò
»á¼û http://test.com£¬½«»áÏÔʾ¡°Hello ThinkPHP£¡¡±£¬¼´¿ª·¢Àֳɡ£
×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑùÔÚµçÄÔÉÏÔËÐÐThinkPHP£¬Í¨¹ýÇéÐÎÉèÖá¢ÏÂÔØ¿ò¼Ü¡¢ÉèÖÃÓ¦ÓóÌÐò¡¢Ê¹ÓÃThinkPHPµÄËĸö°ì·¨£¬¿ìËٵع¹½¨Ò»¸öÍêÕûµÄÍøÕ¾¡£ÐÅÍÐͨ¹ý±¾ÎĵÄѧϰ£¬¶Ô¿ª·¢ÕßÀ´Ëµ£¬ÏàʶThinkPHPµÄ»ù´¡ÖªÊ¶ºÍÓ¦ÓÃÓкܴóµÄ×ÊÖú£¬Äܹ»Ô½·¢¿ìËٵؿª·¢WebÓ¦ÓóÌÐò¡£
ÒÔÉϾÍÊÇÔõôÔÚµçÄÔÔËÐÐthinkphpµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡