thinkphp5ÔõôÉèÖÃ
Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤£¬phpÓïÑÔÒѾ³ÉΪÁ˺ÜÊÇÊ¢ÐеÄÒ»ÖÖweb¿ª·¢ÓïÑÔ£¬¶øthinkphpÔòÊÇphpÖнÏΪÓÅÒìµÄÒ»ÖÖ¿ª·¢¿ò¼Ü¡£±¾ÎĽ«»áÏÈÈÝthinkphp5µÄÉèÖã¬×ÊÖú¸÷È˸üºÃµØʹÓÃÕâ¿î¿ò¼Ü¡£
Ò»¡¢ÇéÐÎÒªÇó
ÔÚ×îÏÈÉèÖÃ֮ǰ£¬ÎÒÃÇÐèÒª¶ÔÇéÐξÙÐÐһЩҪÇó¡£ThinkPHP5ÐèÒªPHP5.4¼°ÒÔÉÏ°æ±¾Ö§³Ö£¬²¢ÇÒÐèÒªMySQL 5.0¼°ÒÔÉÏ°æ±¾¡£ÈôÊÇÄúµÄЧÀÍÆ÷Öª×ãÕâЩÌõ¼þ£¬ÄÇôÎÒÃÇ¿ÉÒÔ×îÏÈÉèÖÃÕâ¸ö¿ò¼ÜÁË¡£
¶þ¡¢Ä¿Â¼½á¹¹¼°ÎļþÓÃ;
ÎÒÃÇÏÈÀ´¿´Ò»ÏÂThinkPHP5µÄĿ¼½á¹¹£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ThinkPHP
©À©¤app Ó¦ÓÃĿ¼
©¦ ©À©¤controller ¿ØÖÆÆ÷Ŀ¼
©¦ ©À©¤model Ä£×ÓĿ¼
©¦ ©¸©¤view ÊÓͼĿ¼
©À©¤config ÉèÖÃÎļþĿ¼
©À©¤public Èë¿ÚÎļþ¼°×ÊԴĿ¼
©¦ ©À©¤static ¾²Ì¬×ÊԴĿ¼
©¦ ©À©¤.htaccess htaccessÎļþ
©¦ ©À©¤favicon.ico Íøվͼ±ê
©¦ ©¸©¤index.php Èë¿ÚÎļþ
©À©¤route ·ÓÉÉèÖÃĿ¼
©À©¤runtime ÔËÐÐʱĿ¼
©À©¤thinkphp ThinkPHP¿ò¼ÜϵͳĿ¼
©À©¤vendor ComposerÀà¿âĿ¼
©À©¤.htaccess htaccessÎļþ
©À©¤composer.json ComposerÉèÖÃÎļþ
©À©¤README.md ¿ò¼Ü˵Ã÷Îļþ
©¸©¤think ÏÂÁîÐÐÈë¿ÚÎļþ
ÆäÖУ¬¸÷Îļþ¼ÐµÄ×÷ÓÃÈçÏ£º
app£ºÓ¦ÓÃĿ¼£¬ÓÃÓÚ´æ·Å¿ØÖÆÆ÷¡¢Ä£×Ó¡¢ÊÓͼµÈÎļþ¡£
config£ºÉèÖÃÎļþĿ¼£¬°üÀ¨Êý¾Ý¿âÉèÖá¢Â·ÓÉÉèÖõȡ£
public£ºÈë¿ÚÎļþ¼°×ÊԴĿ¼£¬°üÀ¨¾²Ì¬×ÊԴĿ¼¡¢Èë¿ÚÎļþ¼°htaccessÎļþ¡£
route£ºÂ·ÓÉÉèÖÃĿ¼£¬ÉèÖ÷ÓɹæÔò¡£
runtime£ºÔËÐÐʱĿ¼£¬°üÀ¨»º´æÎļþ¡¢ÈÕÖ¾ÎļþµÈ¡£
thinkphp£ºThinkPHP¿ò¼ÜϵͳĿ¼£¬°üÀ¨½¹µãÀà¿â¡¢º¯Êý¿âµÈ¡£
vendor£ºComposerÀà¿âĿ¼£¬°üÀ¨ThinkPHPÀ©Õ¹Àà¿â¡¢µÚÈý·½Àà¿âµÈ¡£
.htaccess£ºhtaccessÎļþ£¬ÓÃÓÚURLÖØд¡£
composer.json£ºComposerÉèÖÃÎļþ£¬ÓÃÓÚ°ü¹ÜÀí¡£
README.md£º¿ò¼Ü˵Ã÷Îļþ¡£
think£ºÏÂÁîÐÐÈë¿ÚÎļþ£¬ÓÃÓÚÖ´ÐÐÖÖÖÖÏÂÁî¡£
Èý¡¢Êý¾Ý¿âÉèÖÃ
Êý¾Ý¿âÉèÖÃÎļþÔÚ\ThinkPHP\configĿ¼ÏµÄdatabase.phpÎļþÖУ¬ÎÒÃÇÐèҪƾ֤ÏÖÕæÏàÐÎÉèÖÃÄÚÀïµÄ²ÎÊý£¬ºÃ±ÈÊý¾Ý¿âÖ÷»úµØµã¡¢Êý¾Ý¿âÃû³Æ¡¢Êý¾Ý¿âÓû§ÃûºÍÃÜÂëµÈ¡£
ÏêϸÉèÖÃÒªÁìÈçÏ£º
return [ // Êý¾Ý¿âÀàÐÍ 'type' => 'mysql', // ЧÀÍÆ÷µØµã 'hostname' => 'localhost', // Êý¾Ý¿âÃû 'database' => 'test', // Óû§Ãû 'username' => 'root', // ÃÜÂë 'password' => '', // ¶Ë¿Ú 'hostport' => '', // ÅþÁ¬dsn 'dsn' => '', // Êý¾Ý¿âÅþÁ¬²ÎÊý 'params' => [], // Êý¾Ý¿â±àÂëĬÈϽÓÄÉutf8 'charset' => 'utf8', // Êý¾Ý¿â±íǰ׺ 'prefix' => 'think_', // Êý¾Ý¿âµ÷ÊÔģʽ 'debug' => true, // ¿ªÆô×Ô¶¯Ð´Èëʱ¼ä´Á×ֶΠ'auto_timestamp' => true, // ¿ªÆô×ֶλº´æ 'fields_cache' => true, ];
µÇ¼ºó¸´ÖÆ
ËÄ¡¢Â·ÓÉÉèÖÃ
·ÓÉÉèÖÃÎļþÔÚ\ThinkPHP\routeĿ¼Ï£¬ÈçÐèÒªÉèÖÃURLµØµã±äÁ¿£¬ÔòÐèÒªÐ޸ĸÃĿ¼ÏµÄroute.phpÎļþ£¬ÏêϸÉèÖÃÒªÁìÈçÏ£º
use think\Route; Route::get('hello/:name', 'index/hello');
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëÌåÏÖÉèÖÃÒ»¸ögetÇëÇóµÄ·ÓÉ£¬µ±Óû§»á¼ûhttp://ÄãµÄÓòÃû/hello/abcʱ£¬½«»áÓ³Éäµ½index¿ØÖÆÆ÷µÄhelloÒªÁ죬²¢½«abc×÷ΪҪÁìµÄ²ÎÊý´«Èë¡£
Îå¡¢Ó¦ÓÃÉèÖÃ
Ó¦ÓÃÉèÖÃÎļþÔÚ\ThinkPHP\configĿ¼ÏµÄapp.phpÎļþÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÐ޸ĸÃÎļþÀ´ÉèÖÃÓ¦ÓõÄÉèÖòÎÊý£¬ºÃ±ÈĬÈϵĿØÖÆÆ÷¡¢²Ù×÷ÒªÁìµÈ¡£
ÏêϸÉèÖÃÒªÁìÈçÏ£º
return [ // ĬÈÏ¿ØÖÆÆ÷Ãû 'default_controller' => 'Index', // ĬÈϲÙ×÷Ãû 'default_action' => 'index', // Òì³£´¦ÀíhandleÀà Áô¿ÕʹÓà \think\exception\Handle 'exception_handle' => '', ];
µÇ¼ºó¸´ÖÆ
Áù¡¢Ä£°åÉèÖÃ
Ä£°åÉèÖÃÎļþÔÚ\ThinkPHP\configĿ¼ÏµÄtemplate.phpÎļþÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý¸ÃÎļþÀ´ÉèÖÃÄ£°åÒýÇæµÄ²ÎÊý£¬ºÃ±ÈÉèÖÃÄ£°åµÄ»º´æ·¾¶¡¢±êÇ©Æðʼ±ê¼Ç¡¢±êÇ©¿¢Ê±ê¼ÇµÈ¡£
ÏêϸÉèÖÃÒªÁìÈçÏ£º
return [ // Ä£°åÎļþĿ¼ 'view_path' => '', // Ä£°åºó׺ 'view_suffix' => 'html', // Ä£°åÒýÇæÀàÐÍ Ö§³Ö php think Ö§³ÖÀ©Õ¹ 'type' => 'Think', // Ä£°å·¾¶Ìæ»» 'view_depr' => DIRECTORY_SEPARATOR, // Ä£°åÒýÇæͨË×±êÇ©×îÏȱê¼Ç 'tpl_begin' => '{', // Ä£°åÒýÇæͨË×±êÇ©¿¢Ê±ê¼Ç 'tpl_end' => '}', // ±êÇ©¿â±êÇ©×îÏȱê¼Ç 'taglib_begin' => '{', // ±êÇ©¿â±êÇ©¿¢Ê±ê¼Ç 'taglib_end' => '}', ];
µÇ¼ºó¸´ÖÆ
Æß¡¢×ܽá
ͨ¹ýÒÔÉÏÉèÖÃÒªÁ죬ÎÒÃÇ¿ÉÒÔÎÞаµØʵÏÖ¶ÔThinkPHP5¿ò¼ÜµÄÉèÖ㬴ӶøʹÆä¸üºÃµØÖª×ãÎÒÃǵÄÐèÇó¡£Í¬Ê±£¬ÕâЩÉèÖÃÒ²ÊÇÎÒÃÇÔÚÏÖʵÏîÄ¿¿ª·¢ÖÐÐèÒª¾³£Óõ½µÄÊÖÒÕ¡£Ï£ÍûÕâƪÎÄÕ¶Ը÷ÈËÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇthinkphp5ÔõôÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡