thinkphp5ÔÚÄÇÀï½ç˵³£Á¿
thinkphp5ÊÇÒ»¿îÏÖ´ú»¯µÄphp¿ª·¢¿ò¼Ü£¬Ëü¾ßÓÐÓÅÑŵÄÓï·¨¡¢Ç¿Ê¢µÄ¹¦Ð§ºÍ±ã½ÝµÄ²Ù×÷¡£ÔÚʹÓÃthinkphp5¾ÙÐпª·¢Àú³ÌÖУ¬³£³£»áÉæ¼°µ½³£Á¿µÄ½ç˵¡£±¾ÎĽ«»áÌÖÂÛthinkphp5ÔÚÄÇÀï½ç˵³£Á¿ÒÔ¼°³£Á¿µÄÏà¹Ø֪ʶ¡£
ÔÚthinkphp5ÖУ¬³£Á¿µÄ½ç˵ÓÐÁ½ÖÖ·½·¨£ºÒ»ÖÖÊÇÔÚconfigÉèÖÃÎļþÖнç˵£¬ÁíÒ»ÖÖÊÇÔÚ´úÂëÖÐʹÓÃdefine()º¯Êý½ç˵¡£
ÔÚconfigÉèÖÃÎļþÖнç˵³£Á¿
ÔÚthinkphp5ÖУ¬ÎÒÃÇ¿ÉÒÔÔÚconfigĿ¼ÏÂÃæµÄÎļþÖнç˵³£Á¿¡£ÀýÈ磺config.phpÎļþ£¬½ç˵һ¸ö³£Á¿WEBSITE_NAME£¬´úÂëÈçÏ£º
return [ 'WEBSITE_NAME' => 'My Website', ];
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃreturn·µ»ØÒ»¸öÊý×飬Êý×éµÄ¼üÃûÊdz£Á¿Ãû³Æ£¬ÖµÊdz£Á¿µÄÖµ¡£ÔÚ´úÂëÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨Ê¹Óó£Á¿£º
echo config('WEBSITE_NAME');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃÁËconfigº¯ÊýÀ´»ñÈ¡³£Á¿µÄÖµ¡£Í¨¹ýʹÓÃÕâÖÖ·½·¨£¬ÔÚÕû¸öÓ¦ÓóÌÐòÖпÉÒÔÀû±ãµØʹÓÃÕâ¸ö³£Á¿¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ʹÓÃdefine()º¯Êý½ç˵³£Á¿
³ýÁËÔÚconfigÉèÖÃÎļþÖнç˵³£Á¿Ö®Í⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃPHPÄÚÖú¯Êýdefine()À´½ç˵³£Á¿¡£ÀýÈ磺
// ÔÚÈ«¾Ö½ç˵³£Á¿ define('WEBSITE_NAME', 'My Website'); // ÔÚÀàÖнç˵³£Á¿ class MyClass { const WEBSITE_NAME = 'My Website'; }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃÁËdefine()º¯Êý»®·ÖÔÚÈ«¾ÖºÍÀàÖнç˵ÁËÒ»¸ö³£Á¿¡£ÔÚ´úÂëÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨Ê¹Óó£Á¿£º
echo WEBSITE_NAME; echo MyClass::WEBSITE_NAME;
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇÖ±½ÓʹÓó£Á¿ÃûÀ´»ñÈ¡³£Á¿µÄÖµ¡£
×ܽ᣺
ÔÚthinkphp5ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃconfigÉèÖÃÎļþºÍdefine()º¯ÊýÀ´½ç˵³£Á¿¡£ÎÞÂÛʹÓÃÄÄÖÖ·½·¨£¬¶¼¿ÉÒÔÀû±ãµØÔÚÕû¸öÓ¦ÓóÌÐòÖÐʹÓó£Á¿¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇÓ¦¸Ã×ñÊØPHPµÄ³£Á¿ÃüÃû¹æ·¶£¬Ê¹Óôóд×ÖĸºÍÏ»®Ïß¡°_¡±ÌåÏÖµ¥´Ê¼äµÄÍÑÀë·û¡£Í¬Ê±£¬½ç˵³£Á¿Ö®Ç°Ó¦¸ÃÏȼì²é³£Á¿ÊÇ·ñÒѾ±»½ç˵¹ý£¬ÒÔ×èÖ¹³£Á¿µÄÖظ´½ç˵¡£
ÒÔÉϾÍÊÇthinkphp5ÔÚÄÇÀï½ç˵³£Á¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡