thinkphp ÖØд»ùÀàÒªÁì
thinkphpÊÇÒ»¿î¹ãÊܽӴýµÄphp¿ª·¢¿ò¼Ü£¬ÌṩÁ˸»ºñµÄ¹¦Ð§ºÍ±ã½ÝµÄ¿ª·¢·½·¨¡£ÔÚʹÓÃthinkphpÀú³ÌÖУ¬ÓÐʱ¼äÎÒÃÇÐèÒª¶Ô¿ò¼ÜµÄ½¹µã´úÂë¾ÙÐÐÐ޸ģ¬ÒÔÖª×ãÎÒÃǵÄÏêϸÐèÇó¡£ÆäÖУ¬ÖØд»ùÀàÒªÁìÊÇÒ»ÖÖ³£¼ûµÄÐ޸ķ½·¨¡£
»ùÀàÊÇÖ¸¿ò¼ÜÖн¹µã´úÂëÖеĻù´¡À࣬Ëü°üÀ¨Ðí¶àÖ÷ÒªµÄÒªÁì¡£¶øÖØд»ùÀàÒªÁìÊÇÖ¸ÔÚ²»¸Ä±ä»ùÀàµÄÔÓй¦Ð§µÄÇéÐÎÏ£¬ÐÞ¸Äij¸öÒªÁìµÄÐÐΪ£¬ÒÔ˳ӦµÄÎÒÃǵĿª·¢ÐèÒª¡£±¾ÎĽ«ÏÈÈÝThinkPHPÔõÑùÖØд»ùÀàÒªÁì¡£
½¨ÉèÀ©Õ¹Àà
ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý½¨ÉèÀ©Õ¹ÀàÀ´ÖØд»ùÀàÒªÁì¡£À©Õ¹ÀàÊÇÖ¸ÔÚ¿ò¼ÜµÄ»ù´¡ÉϾÙÐÐÀ©Õ¹µÄÀà¡£ÎÒÃÇ¿ÉÒÔÔÚÓ¦ÓÃĿ¼ÏµÄextendĿ¼Öн¨ÉèÀ©Õ¹ÀàÎļþ£¬²¢ÇÒÀàµÄÃüÃû¿Õ¼äÐèÒªºÍ¿ò¼ÜÏàͬ¡£ÀýÈ磬ÈôÊÇÎÒÃÇÐèÒªÖØд¿ØÖÆÆ÷»ùÀàµÄÒªÁ죬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒÔÏÂÎļþ£º
<?php namespace thinklibrarycontroller; use thinkController; class Base extends Controller { //ÖØдҪÁì protected function _initialize() { //еĴúÂë } }
µÇ¼ºó¸´ÖÆ
ÔÚÀ©Õ¹ÀàÖУ¬ÎÒÃÇÐèÒª¼ÌÐø±»ÖØдµÄ»ùÀ࣬ȻºóÖØдÐèÒªÐ޸ĵÄÒªÁì¼´¿É¡£ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇÖØдÁË¿ØÖÆÆ÷»ùÀàÖеÄ_initialize()ÒªÁì¡£
ÖØд¶ÁÈ¡Æ÷ºÍÉèÖÃÆ÷
³ýÁËÖØдͨË×µÄÒªÁìÖ®Í⣬ÓÐʱ¼äÎÒÃÇÒ²ÐèÒªÖØд»ùÀàÖеĶÁÈ¡Æ÷ºÍÉèÖÃÆ÷¡£¶ÁÈ¡Æ÷ÊÇÖ¸ÓÃÓÚ»á¼ûÀàÖÐ˽ÓкÍÊܱ£»¤ÊôÐÔµÄÒªÁ죬¶øÉèÖÃÆ÷ÔòÊÇÉèÖÃÊôÐÔÖµµÄÒªÁì¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÒªÖØд¶ÁÈ¡Æ÷ºÍÉèÖÃÆ÷£¬ÎÒÃÇÐèÒªÔÚÀ©Õ¹ÀàÖнç˵ͬÃûµÄÒªÁ죬²¢ÇÒʹÓÃparent::ŲÓûùÀàÖеÄÒªÁì¡£ÀýÈ磬ÎÒÃÇÐèÒªÖØдModel»ùÀàÖеĶÁÈ¡Æ÷ºÍÉèÖÃÆ÷£¬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒÔÏÂÎļþ£º
<?php namespace thinklibrarymodel; use thinkModel; class Base extends Model { //ÖØд¶ÁÈ¡Æ÷ public function __get($name) { //еĴúÂë return parent::__get($name); } //ÖØдÉèÖÃÆ÷ public function __set($name, $value) { //еĴúÂë parent::__set($name, $value); } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇÖØдÁËModel»ùÀàÖеÄ__get()ºÍ__set()ÒªÁì¡£
ʹÓÃÖØдµÄÒªÁì
ÔÚÀ©Õ¹ÀàÖÐÖØд»ùÀàÒªÁìÖ®ºó£¬ÎÒÃÇÐèÒªÔÚÏÖʵ¿ª·¢ÖÐʹÓÃÖØдµÄÒªÁì¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚÓ¦ÓÃĿ¼ÏµÄconfigĿ¼ÖеÄÎļþÖÐÐÞ¸ÄÉèÖÃÏîÀ´Ö¸¶¨Ê¹ÓÃÀ©Õ¹ÀàÖеÄÒªÁì¡£
ÀýÈ磬ÔÚÖØдÁË¿ØÖÆÆ÷»ùÀàµÄ_initialize()ÒªÁìºó£¬ÎÒÃÇ¿ÉÒÔ½«¸ÃÀ©Õ¹ÀàÖ¸¶¨ÎªÓ¦ÓóÌÐòµÄĬÈÏ¿ØÖÆÆ÷»ùÀࣺ
//config.phpÎļþÖÐÌí¼ÓÒÔÏ´úÂë 'controller' => 'appindexcontrollerAuth',
µÇ¼ºó¸´ÖÆ
ÐèҪעÖصÄÊÇ£¬ÎÒÃÇÐèÒªÔÚÓ¦ÓÃĿ¼ÏµÄÎļþÖÐÐÞ¸ÄÉèÖÃÏ¶ø²»ÊÇ¿ò¼ÜµÄ½¹µã´úÂëÎļþ¡£ÕâÑùµ±ÎÒÃÇÉý¼¶¿ò¼Üʱ£¬ÎÒÃÇÖØдµÄÒªÁì²»»á±»ÁýÕÖ¡£
½áÂÛ
ÖØд»ùÀàÒªÁìÊÇÒ»ÖÖÎÞаµÄÐ޸Ŀò¼ÜÔÓдúÂëµÄ·½·¨¡£Í¨¹ýʹÓÃÀ©Õ¹À࣬ÎÒÃÇ¿ÉÒÔÔÚ²»¸Ä±ä¿ò¼ÜµÄÔÓй¦Ð§µÄÇéÐÎÏ£¬Öª×ãÎÒÃǵÄÏêϸÐèÇó¡£ÔÚά»¤´úÂëºÍÉý¼¶¿ò¼Üʱ£¬ÎÒÃÇÒ²¿ÉÒÔºÜÀû±ãµØµ¼³öÐ޸ĵÄÄÚÈÝ£¬°ü¹Ü´úÂëµÄ¿Éά»¤ÐÔ¡£
ÒÔÉϾÍÊÇthinkphp ÖØд»ùÀàÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡