thinkphpÔõô¼ÓÔØ
thinkphpµÄ×Ô¶¯¼ÓÔع¦Ð§ÊÇ¿ª·¢thinkphpÓ¦ÓóÌÐòʱ±Ø²»¿ÉÉÙµÄÒ»ÏЧ£¬Äܹ»×ÊÖú¿ª·¢ÕßÔ½·¢¿ìËٵؾÙÐпª·¢¡£Òò´Ë£¬ÊìÁ·ÕÆÎÕthinkphpµÄ×Ô¶¯¼ÓÔع¦Ð§¹ØÓÚ¿ª·¢ÕßÀ´ËµºÜÊÇÖ÷Òª¡£
ÒÔÏÂÊÇһЩ¹ØÓÚThinkPHP×Ô¶¯¼ÓÔصÄÏÈÈݺÍʹÓÃÒªÁ죺
1.×Ô¶¯¼ÓÔØÔÀí£º
»ù±¾ÉÏ£¬ThinkPHPµÄ×Ô¶¯¼ÓÔØÊÇͨ¹ýPHPµÄħÊõÒªÁì__autoload()À´ÊµÏֵġ£µ±ÒýÓÃÒ»¸öδ½ç˵µÄÀàʱ£¬PHPÒýÇæ»á×Ô¶¯Å²ÓÃ__autoload()ÒªÁ죬½«ÐèÒªµÄÀà´ÓÖ¸¶¨µÄĿ¼ÖÐÔØÈë¡£
2.×Ô¶¯¼ÓÔØʹÓÃÒªÁ죺
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚThinkPHPÖУ¬×Ô¶¯¼ÓÔع¦Ð§ÊÇĬÈÏ¿ªÆôµÄ£¬ÒÔÊÇÔÚ¾ø´ó´ó¶¼ÇéÐÎÏ£¬Äú²»ÐèÒª¾ÙÐÐÈκεÄÊÖ¶¯ÉèÖá£Ö»ÐèÒªÔÚÄúµÄ´úÂëÖÐʹÓÃËùÐèµÄÀ࣬ϵͳ¾Í»á×Ô¶¯Ñ°ÕÒ¶ÔÓ¦µÄÀàÎļþ£¬²¢½«ÆäÔØÈë¡£
ÈôÊÇÄúÐèÒªÊÖ¶¯¼ÓÔØij¸öÀ࣬ÄÇô¿ÉÒÔʹÓÃThinkPHPÌṩµÄautoload()º¯Êý£¬¸Ãº¯Êý¿ÉÒÔ¼ÓÔØÈκÎÒ»¸öÀàÎļþ¡£ÀýÈ磺
<?php autoload('SomeClass'); ?>
µÇ¼ºó¸´ÖÆ
3.ÀàµÄ×Ô¶¯¼ÓÔØ˳Ðò£º
ÔÚ¼ÓÔØÀàʱ£¬ThinkPHPƾ֤ÒÔÏÂ˳Ðò¾ÙÐвéÕÒ£º
¢Ù ÄÚºËÀà¿â£¨ThinkPHP\Library\Think¡¢ThinkPHP\Library\BehaviorµÈ£©£»
¢Ú Ä¿½ñÓ¦ÓÃÀà¿â£¨APP_PATH.’Common/Behavior’µÈ£©£»
¢Û Ä¿½ñ¿ØÖÆÆ÷ÀàĿ¼£¨MODULE_NAME.’/Controller’µÈ£©ÏµÄÀàÎļþ£»
¢Ü Ä¿½ñÄ£×ÓÀàĿ¼£¨MODULE_NAME.’/Model’µÈ£©ÏµÄÀàÎļþ¡£
ÈôÊÇÄúµÄÀàÃû³ÆÓëThinkPHP×Ô´øµÄÀàÖØÃû£¬ÄÇôThinkPHPµÄ×Ô¶¯¼ÓÔØÓÅÏÈʹÓÃÄúËù×Ô½ç˵µÄÀà¡£
4.×Ô½ç˵Àà¿âµÄ×Ô¶¯¼ÓÔØÒªÁ죺
ÈôÊÇÄúÐèÒª×Ô½ç˵һ¸öÀà¿â£¬ÈÃËüÄܹ»±»ThinkPHPµÄ×Ô¶¯¼ÓÔØ»úÖÆËùʶ±ð£¬Äú¿ÉÒÔ½«¸ÃÀà¿âĿ¼¼ÓÈëµ½APP_PATHϵÄÎļþ¼ÐÖУ¨ÀýÈ磺APP_PATH.’MyLibs’£©£¬²¢ÇÒÔÚ¸ÃĿ¼ÏÂн¨autoload.phpÎļþ£¬¸ÃÎļþÐèÒª°üÀ¨Ò»¸öº¯Êý£¬ÓÃÓÚÖ´ÐÐÀàµÄÔØÈë²Ù×÷¡£ÀýÈ磺
<?php spl_autoload_register(function ($class){ $file = APP_PATH . str_replace('\\', '/', $class) . '.php'; if (is_file($file)) { include $file; } }); ?>
µÇ¼ºó¸´ÖÆ
5.×Ô¶¯¼ÓÔصĻº´æ£º
ThinkPHPµÄ×Ô¶¯¼ÓÔØ»úÖÆ¿ÉÒÔ½«³£ÓõÄÀàÎļþ»º´æµ½ÄÚ´æÖУ¬Ìá¸ßÐÔÄÜ¡£Äú¿ÉÒÔÔÚÉèÖÃÎļþÖÐÉèÖãº
return array( 'app_init'=>array('Common\Behavior\InitHookBehavior'), 'autocache' => true );
µÇ¼ºó¸´ÖÆ
ÕâÀïÎÒÃÇ¿ªÆôÁË×Ô¶¯¼ÓÔصĻº´æ¹¦Ð§£¬½«ÆôÓÃapp_init¹³×Ó£¬²¢Ôڸù³×ÓÖÐÖ´ÐÐÁËÒ»¸öInitHookBehaviorÀàµÄ³õʼ»¯²Ù×÷¡£
×ÛÉÏËùÊö£¬¿ÉÒÔ¿´³öThinkPHPµÄ×Ô¶¯¼ÓÔØ»úÖƺÜÊÇÎÞаºÍ¼òÆÓ£¬¿ª·¢Õß¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó¾ÙÐÐÏìÓ¦µÄÉèÖá£Í¬Ê±£¬Ê¹ÓÃ×Ô¶¯¼ÓÔØ»úÖÆÄܹ»¼«´óµØ¼ÓËÙ¿ª·¢Ð§ÂÊ£¬²¢Ìá¸ßÓ¦ÓóÌÐòµÄÐÔÄÜ¡£
ÒÔÉϾÍÊÇthinkphpÔõô¼ÓÔصÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡