thinkphp5 Ä£°å²»¿É×Ô¶¯¼ÓÔØ
ÔõÑù½â¾öthinkphp5Ä£°å²»¿É×Ô¶¯¼ÓÔصÄÎÊÌâ
ÔÚ¾ÙÐÐthinkphp5¿ò¼Ü¿ª·¢µÄÀú³ÌÖУ¬ÎÒÃǾ³£»áʹÓÃÄ£°åäÖȾÀ´äÖȾҳÃ棬µ«ÓÐʱÎÒÃÇÈ´»áÓöµ½Ò»¸öÎÊÌ⣬¾ÍÊÇÄ£°åÎÞ·¨×Ô¶¯¼ÓÔصÄÎÊÌâ¡£Õâ¸öÎÊÌâ¹ØÓÚһЩÐÂÊÖ³ÌÐòÔ±À´Ëµ¿ÉÄܽÏÁ¿À§ÈÅ£¬ÄÇô£¬±¾ÆªÎÄÕ½«»áÏÈÈÝһЩ³£¼ûµÄ½â¾öÒªÁ죬×ÊÖú¸÷È˸üºÃµØ½â¾öÕâ¸öÎÊÌâ¡£
Ê×ÏÈ£¬ÎÒÃÇÀ´ÏàʶһÏÂthinkphp5Ä£°åµÄ×Ô¶¯¼ÓÔØ»úÖÆ¡£
ÔÚthinkphp5¿ò¼ÜÖУ¬Ä£°å»á×Ô¶¯Æ¾Ö¤¿ØÖÆÆ÷µÄÃüÃû¹æÔò£¬²éÕÒ¶ÔÓ¦µÄÄ£°åÎļþ¾ÙÐÐäÖȾ¡£ÀýÈ磬ÓÐÒ»¸ö¿ØÖÆÆ÷Îļþ½Ð×öIndex.php£¬ÄÇô¿ò¼Ü»áĬÈÏÈ¥²éÕÒ/views/Index/index.htmlÄ£°åÎļþ¡£¶øÔÚÄ£°åÎļþÖУ¬¿ÉÒÔͨ¹ýʹÓÃһЩ¼òÆÓµÄÓï·¨£¬¾ÙÐбäÁ¿Êä³ö¡¢Ìõ¼þÅжϡ¢Ñ»·±éÀúµÈ²Ù×÷¡£ÀýÈ磬¿ÉÒÔʹÓÃ{{$name}}À´Êä³ö$name±äÁ¿µÄÖµ¡£
µ«ÈôÊÇÎÒÃÇ·¢Ã÷ʹÓÃÉÏÊöÓï·¨¾ÙÐÐÄ£°åäÖȾµÄʱ¼ä£¬¿ØÖÆÆ÷¶ÔÓ¦µÄÄ£°åÎÞ·¨±»×Ô¶¯¼ÓÔØ£¬ÄÇôÕâʱ¼ä¾ÍÐèÒªÅŲéÏà¹ØµÄÎÊÌâÏ¢Õù¾öÒªÁìÁË¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
³£¼ûÎÊÌâÅŲ飺
¼ì²éÄ£°åÎļþ·¾¶ÊÇ·ñ׼ȷ¡£
ÔÚthinkphp5¿ò¼ÜÖУ¬Ä£°åÎļþ´æ·ÅÔÚ/viewsÎļþ¼ÐÖУ¬¶ÔÓ¦µÄ¿ØÖÆÆ÷¶ÔÓ¦µÄÄ£°åÎļþÓ¦¸Ã´æ·ÅÔÚ/views/¿ØÖÆÆ÷Ãû/ÎļþÃû.htmlÖС£Òò´Ë£¬ÎÒÃÇÐèÒª¼ì²éÒ»ÏÂ×Ô¼ºµÄÄ£°åÎļþ·¾¶ÊÇ·ñ׼ȷ£¬ÊÇ·ñ·ÅÔÚÁË׼ȷµÄÎļþ¼ÐÖУ¬ÒÔ¼°ÎļþÃûÊÇ·ñ׼ȷ¡£
¼ì²é¿ØÖÆÆ÷ÊÇ·ñ׼ȷÃüÃû¡£
ÈçÇ°ËùÊö£¬thinkphp5¿ò¼ÜµÄÄ£°å×Ô¶¯¼ÓÔØ»úÖÆÊÇƾ֤¿ØÖÆÆ÷µÄÃüÃû¹æÔòÀ´²éÕÒ¶ÔÓ¦µÄÄ£°åÎļþµÄ¡£Òò´Ë£¬ÈôÊÇÎÒÃǵĿØÖÆÆ÷ÃüÃû²»ÇкϹ淶£¬ÄÇôҲ»áµ¼ÖÂÄ£°åÎÞ·¨×Ô¶¯¼ÓÔØ¡£×¼È·µÄ¿ØÖÆÆ÷ÃüÃû¹æÔòÓ¦¸ÃÊÇÍÕ·åʽÃüÃû£¬ÀýÈçIndexController¡¢GoodsControllerµÈµÈ¡£
¼ì²éÄ£°åÎļþÃüÃûÊÇ·ñ׼ȷ¡£
ÔÚthinkphp5¿ò¼ÜÖУ¬Ä£°åÎļþÃüÃûÓ¦¸ÃÓë¶ÔÓ¦¿ØÖÆÆ÷ϵÄÄ£°åÎļþÃûÒ»Ö¡£ÀýÈ磬Index¿ØÖÆÆ÷ϵÄÄ£°åÎļþÓ¦¸Ã½Ð×öindex.html¡£ÈôÊÇ¿ØÖÆÆ÷ϵÄÄ£°åÎļþÃüÃû²»×¼È·£¬Ò²»áµ¼ÖÂÄ£°åÎÞ·¨×Ô¶¯¼ÓÔØ¡£
¼ì²éÊÇ·ñÓÐʹÓûº´æ¡£
ÓÐʱ¼äÎÒÃÇÔÚ¾ÙÐÐÄ£°åäÖȾµÄʱ¼ä£¬¿ªÆôÁË»º´æ¡£Õâʱ¼äÈôÊÇÎÒÃǸüÐÂÁËÄ£°åÎļþ£¬µ«»º´æ²¢Ã»Óб»É¨³ýµÄ»°£¬ÄÇô¾Í»áµ¼ÖÂеÄÄ£°åÎÞ·¨±»¼ÓÔØ¡£Òò´Ë£¬ÈôÊÇÎÒÃÇÔÚ¾ÙÐÐÄ£°åäÖȾʱÓöµ½×Ô¶¯¼ÓÔØÎÊÌ⣬¿ÉÒÔʵÑéɨ³ý»º´æÀ´½â¾ö¡£
½â¾öÒªÁ죺
¼ì²éÄ£°åÎļþ·¾¶
ÔÚÅŲéÁËÉÏÊö³£¼ûÎÊÌâÖ®ºó£¬ÈôÊÇÄ£°åÕÕ¾ÉÎÞ·¨×Ô¶¯¼ÓÔØ£¬ÎÒÃÇ¿ÉÒÔʵÑéÊÖ¶¯äÖȾģ°å¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´ÊÖ¶¯äÖȾģ°å£º
public function index() { $view = new hinkView(); $view->assign('name', 'Hello,World'); return $view->fetch('index',['name'=>$name]); }
µÇ¼ºó¸´ÖÆ
Ç¿ÖÆÖ¸¶¨Ä£°å·¾¶ºÍÎļþÃû
ÈôÊÇÊÖ¶¯äÖȾģ°åÕÕ¾ÉÎÞ·¨½â¾öÎÊÌ⣬ÎÒÃÇ¿ÉÒÔʵÑéʹÓÃÇ¿ÖÆÖ¸¶¨Ä£°å·¾¶ºÍÎļþÃûµÄÒªÁìÀ´½â¾ö¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖмÓÈëÒÔÏ´úÂ룺
public function index() { return $this->fetch(ROOT_PATH . 'views/index/index.html'); }
µÇ¼ºó¸´ÖÆ
ÕâÑùÎÒÃǾͿÉÒÔÖ±½ÓÖ¸¶¨Ä£°åµÄ·¾¶ºÍÎļþÃû£¬¿ÉÒÔÓÐÓõؽâ¾ö×Ô¶¯¼ÓÔØÎÊÌâ¡£
ÐÞ¸ÄconfigÉèÖÃÎļþ
×îºó£¬ÈôÊÇÒÔÉÏÒªÁìÈÔÈ»ÎÞ·¨½â¾öÎÊÌ⣬ÎÒÃÇ¿ÉÒÔʵÑéÐÞ¸ÄconfigÉèÖÃÎļþÖеÄÏà¹ØÉèÖÃÀ´½â¾ö¡£ÎÒÃÇ¿ÉÒÔÔÚconfig.phpÎļþÖмÓÈëÒÔÏ´úÂ룺
'view_replace_str' => [ '__PUBLIC__'=>'/static', '__ROOT__' => '/', '__INDEX__' => '/index.php/Index', ],
µÇ¼ºó¸´ÖÆ
ÕâÑùÎÒÃǾͿÉÒÔÔÚäÖȾģ°åʱ£¬ÒÔ /Index/index.html µÄ·½·¨¾ÙÐмÓÔØÄ£°åÎļþ£¬ÓÐÓõؽâ¾ö×Ô¶¯¼ÓÔØÎÊÌâ¡£
×ܽ᣺
Ä£°å×Ô¶¯¼ÓÔØÎÊÌâÊÇthinkphp5¿ò¼Ü¿ª·¢ÖеÄÒ»¸ö½ÏÁ¿³£¼ûµÄÎÊÌ⣬µ«ËüÒ²ÊǽÏÁ¿ÈÝÒ×½â¾öµÄÎÊÌâ¡£ÈôÊÇÓöµ½ÁËÕâÑùµÄÎÊÌ⣬ÎÒÃÇ¿ÉÒÔƾ֤ÒÔÉÏÒªÁì¾ÙÐÐÅŲéÏ¢Õù¾ö£¬ÈÃÎÒÃǵÄthinkphp5¿ò¼Ü¿ª·¢¸üΪ˳³©¡£
ÒÔÉϾÍÊÇthinkphp5 Ä£°å²»¿É×Ô¶¯¼ÓÔصÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡