×ðÁú¿­Ê±¹ÙÍøµÇ¼

thinkphpÔõôŲÓÃÁíÒ»¸öÀàÄÚÀïµÄÒªÁì

thinkphp ×÷Ϊһ¿îÓÅÒìµÄ php ¿ª·¢¿ò¼Ü £¬¹ãÊÜ¿ª·¢Õßϲ»¶¡£ÔÚ¿ª·¢Àú³ÌÖÐ £¬ÎÒÃǾ­³ £»áдÐí¶àÀà £¬ÓÐʱ¼äÐèÒªÔÚÄ¿½ñÀàÖÐʹÓÃÁíÒ»¸öÀàµÄÒªÁì»òÊôÐÔ £¬ÄÇô¸ÃÔõô×öÄØ £¿±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ thinkphp ÖÐŲÓÃÁíÒ»¸öÀàµÄÒªÁì¡£

Ò»¡¢µ¼ÈëÀà

ҪʹÓÃÁíÒ»¸öÀàµÄÒªÁì £¬µÚÒ»²½ËäÈ»ÊÇÒª½«¸ÃÀàÒýÈ뵽Ŀ½ñÀàÖС£ÔÚ ThinkPHP ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓà import º¯ÊýÀ´ÊµÏÖ£º

import('ÃüÃû¿Õ¼ä.ÀàÃû');

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬ÃüÃû¿Õ¼ä ºÍ ÀàÃû »®·ÖÊDZ»µ¼ÈëÀàµÄÃüÃû¿Õ¼äºÍÀàÃû¡£ÈôÊDZ»µ¼ÈëµÄÀ಻ÔÚÈκÎÃüÃû¿Õ¼äÏ £¬Ö±½Ó½«ÀàÃû´«¸ø import º¯Êý¼´¿É¡£

ÀýÈç £¬ÎÒÃÇÓÐÒ»¸öÀà OtherClass £¬ÆäÖаüÀ¨Ò»¸öÒªÁì test £¬ÏÖÔÚÒªÔÚÄ¿½ñÀàÖÐʹÓøÃÒªÁì £¬¿ÉÒÔÕâÑùд£º

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

import('app\MyClass\OtherClass');
class MyClass {
    public function test() {
        $other = new OtherClass();
        $other->test();
    }
}

µÇ¼ºó¸´ÖÆ

ÕâÑù¾Í¿ÉÒÔÔÚ MyClass ÖÐʹÓà OtherClass ÖÐµÄ test ÒªÁìÁË¡£

¶þ¡¢ÊµÀý»¯Àà

ÔÚµ¼ÈëÀàÖ®ºó £¬ÎÒÃÇ»¹ÐèÒªÓà new Òªº¦×ÖʵÀý»¯¸ÃÀà £¬²Å»ªÊ¹ÓøÃÀàÖеÄÒªÁìºÍÊôÐÔ¡£Í¨³£ÇéÐÎÏ £¬ÎÒÃÇÔÚÄ¿½ñÀàµÄ½á¹¹ÒªÁìÖÐʵÀý»¯±»µ¼ÈëÀà¡£ÀýÈ磺

import('app\MyClass\OtherClass');

class MyClass {
    private $other;
    public function __construct() {
        $this->other = new OtherClass();
    }
    public function test() {
        $this->other->test();
    }
}

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÔڽṹҪÁìÖÐ £¬ÎÒÃÇʵÀý»¯ÁË OtherClass £¬²¢½«Æ丳ֵ¸øÁË MyClass µÄ˽ÓÐÊôÐÔ $other¡£È»ºóÔÚ test ÒªÁìÖÐ £¬ÎÒÃÇ¿ÉÒÔŲÓà $other ¹¤¾ßÖÐµÄ test ÒªÁìÁË¡£

Èý¡¢Å²ÓÃÒªÁì

ÔÚʵÀý»¯±»µ¼ÈëµÄÀàÖ®ºó £¬ÎÒÃǾͿÉÒÔʹÓøÃÀàÖеÄÒªÁìÁË¡£ÔÚŲÓÃÒªÁì֮ǰ £¬ÎÒÃÇÐèÒªÏÈÏàʶĿ½ñÀàÓë±»µ¼ÈëÀàÖ®¼äµÄ¹Øϵ¡£

¸¸×Ó¹Øϵ

ÈôÊÇÄ¿½ñÀàÊDZ»µ¼ÈëÀàµÄ×ÓÀà £¬ÎÒÃÇ¿ÉÒÔÖ±½ÓʹÓà parent Òªº¦×ÖŲÓñ»µ¼ÈëÀàµÄÒªÁì¡£ÀýÈ磺

import('app\MyClass\OtherClass');

class MyClass extends OtherClass {
    public function test() {
        parent::test();
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚ MyClass ÖÐ £¬ÎÒÃǼÌÐøÁË OtherClass £¬²¢ÖØдÁË test ÒªÁì £¬¿ÉÊÇÎÒÃÇ»¹ÏëʹÓà OtherClass ÖÐµÄ test ÒªÁì £¬¿ÉÒÔʹÓà parent::test() À´Å²Óá£

ÏàÖú¹Øϵ

ÈôÊÇÄ¿½ñÀàÓë±»µ¼ÈëÀ಻ÊǸ¸×Ó¹Øϵ £¬¶øÊÇÏàÖú¹Øϵ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýʵÀý»¯±»µ¼ÈëÀàµÄ¹¤¾ßÀ´Å²ÓøÃÀàµÄÒªÁì¡£ÀýÈ磺

import('app\MyClass\OtherClass');

class MyClass {
    private $other;
    public function __construct() {
        $this->other = new OtherClass();
    }
    public function test() {
        $this->other->test();
    }
}

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬MyClass Óë OtherClass Ö®¼ä²¢Ã»ÓмÌÐø¹Øϵ £¬ÎÒÃÇͨ¹ýʵÀý»¯ $other ¹¤¾ßÀ´Å²Óà OtherClass ÖÐµÄ test ÒªÁì¡£

×ܽá

ÒÔÉϾÍÊÇÔÚ ThinkPHP ÖÐŲÓÃÁíÒ»¸öÀàµÄÒªÁìµÄÒªÁì¡£ÎÞÂÛÊǸ¸×Ó¹ØÏÃ÷ÈÕÕ¾ÉÏàÖú¹Øϵ £¬ÎÒÃǶ¼¿ÉÒÔͨ¹ý import º¯Êýµ¼ÈëҪʹÓõÄÀà £¬ÊµÀý»¯ºó¾Í¿ÉÒÔŲÓÃÆäÒªÁìÁË¡£¹ØÓÚ¾­³£ÐèҪŲÓõÄÀà»òÒªÁì £¬¿ÉÒÔÔÚ ThinkPHP µÄÈ«¾ÖÎļþÖнç˵³£Á¿»òº¯Êý £¬Àû±ãÔÚÏîÄ¿µÄÈκÎλÖÃŲÓá£

ÒÔÉϾÍÊÇthinkphpÔõôŲÓÃÁíÒ»¸öÀàÄÚÀïµÄÒªÁìµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ