ThinkPHPÊÇ·ñÖ§³Ö»á¼û¾²Ì¬ÒªÁì
thinkphpÊÇÒ»¸öphp¿ª·¢¿ò¼Ü£¬ËüÌṩÁËÐí¶à±ã½ÝµÄ¹¦Ð§ºÍÒªÁ죬Äܹ»×ÊÖúphp³ÌÐòÔ±Ô½·¢¸ßЧµØ¿ª·¢ÏîÄ¿¡£ÔÚ¾ÙÐпª·¢Ê±£¬ÎÒÃǾ³£»áÓöµ½ÐèÒª»á¼û¾²Ì¬ÒªÁìµÄÇéÐΣ¬ÄÇô£¬thinkphpÊÇ·ñÖ§³Ö»á¼û¾²Ì¬ÒªÁìÄØ£¿
ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýŲÓÃÀàµÄ¾²Ì¬ÒªÁìÀ´ÊµÏÖ»á¼û¾²Ì¬ÒªÁ졣ʹÓþ²Ì¬ÒªÁìʱ£¬ÐèҪעÖØÒÔϼ¸µã£º
ŲÓþ²Ì¬ÒªÁìµÄÓï·¨ÃûÌÃΪ£ºÀàÃû::ÒªÁìÃû()£¬ÆäÖÐÀàÃûºóÃæÐè¼ÓÉÏ˫ðºÅ¡£
ÔÚThinkPHPÖУ¬¿ÉÒÔ½«¾²Ì¬ÒªÁì·â×°ÔÚÀàÒªÁìÖУ¬ÒÔÀû±ãŲÓá£ÀýÈ磺
class Demo { public static function staticMethod() { // ¾²Ì¬ÒªÁìʵÏÖ´úÂë } public function demoMethod() { // ÀàÒªÁìʵÏÖ´úÂë self::staticMethod(); // ŲÓþ²Ì¬ÒªÁì } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃǽ«¾²Ì¬ÒªÁì·â×°ÔÚÀàÒªÁìÖУ¬²¢Í¨¹ýself::staticMethod()µÄ·½·¨À´Å²Óþ²Ì¬ÒªÁì¡£
ÔÚThinkPHPµÄ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇÒ²¿ÉÒÔ»á¼û¾²Ì¬ÒªÁì¡£ÀýÈ磺
namespace app\controller; use app\BaseController; class Index extends BaseController { public function index() { \app\Demo::staticMethod(); // ŲÓþ²Ì¬ÒªÁì } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇͨ¹ýnamespaceÖ¸¶¨ÁËapp\DemoÀàËùÔÚµÄλÖ㬲¢ÇÒÔÚ»á¼ûʱÐèÒª¼ÓÉÏ\\À´×èÖ¹ÓëÃüÃû¿Õ¼ä±¬·¢³åÍ»¡£
×îºó£¬ÐèҪעÖصÄÊÇ£¬»á¼û¾²Ì¬ÒªÁìʱÐèÒª°ü¹Ü¸ÃÒªÁìµÄ¿É¼ûÐÔΪpublic£¬²»È»¿ÉÄܻᵼÖÂÎÞ·¨»á¼ûµÄÎÊÌâ¡£
×ÛÉÏËùÊö£¬ThinkPHPÊÇÖ§³Ö»á¼û¾²Ì¬ÒªÁìµÄ¡£Í¨¹ýÀàÃû::ÒªÁìÃû()µÄ·½·¨£¬ÎÒÃÇ¿ÉÒÔÔÚThinkPHPÖÐÀû±ãµØ»á¼û¾²Ì¬ÒªÁ죬Ìá¸ß¿ª·¢Ð§ÂÊ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÒÔÉϾÍÊÇThinkPHPÊÇ·ñÖ§³Ö»á¼û¾²Ì¬ÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡