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

ÔõÑùʹÓÃThinkPHP 5.1µÄÈÝÆ÷

thinkphp 5.1ÊÇÖйú×îÊܽӴýµÄphp¿ò¼ÜÖ®Ò»¡£ËüµÄÈÝÆ÷¾ÍÊÇÆäÖÐÒ»¸öÖ÷ÒªµÄ×é¼þ¡£ÈÝÆ÷ÊÇÒ»ÖÖÓÃÓÚ´¦ÀíÒÀÀµ×¢ÈëµÄÊÖÒÕ¡£±¾ÎĽ«ÌÖÂÛÈÝÆ÷ÊÇʲô¡¢ÎªÊ²Ã´ÐèÒªÈÝÆ÷ £¬ÒÔ¼°ÔõÑùʹÓÃthinkphp 5.1µÄÈÝÆ÷¡£

Ò»¡¢ÈÝÆ÷ÊÇʲô£¿

ÈÝÆ÷ÊÇÒ»ÖÖģʽ £¬ÓÃÓÚÖÎÀíºÍ×éÖ¯¹¤¾ßµÄ½¨Éè¡¢Ïú»ÙºÍÉúÃüÖÜÆÚ¡£ËüÒ²¿ÉÒÔ´¦Àí¹¤¾ßÖ®¼äµÄÒÀÀµ¹Øϵ¡£ÈÝÆ÷ά»¤Ò»¸ö¹¤¾ßµÄ×¢²á±í £¬¸Ã×¢²á±í´æ´¢ÁËËùÓй¤¾ßµÄʵÀý £¬²¢ÎªÓ¦ÓóÌÐòÌṩ¶ÔÕâЩʵÀýµÄ»á¼û¡£ÈôÊÇÓ¦ÓóÌÐòÐèÒªÒ»¸ö¹¤¾ß £¬¿ÉÒÔ´ÓÈÝÆ÷ÖлñÈ¡Ëü £¬¶ø²»ÊÇÖ±½Ó½¨É蹤¾ß¡£

¶þ¡¢ÎªÊ²Ã´ÐèÒªÈÝÆ÷£¿

ÔڹŰåµÄPHP¿ª·¢ÖÐ £¬ÎªÁËʹÓÃij¸ö¹¤¾ß £¬ÎÒÃÇͨ³£ÊÇÔÚ´úÂëÖн¨ÉèʵÀý¹¤¾ß £¬È»ºóÖ±½ÓŲÓÃÕâ¸ö¹¤¾ßµÄÒªÁì¡£ÎÒÃÇÒ²¿ÉÒÔʹÓÃÈ«¾Ö±äÁ¿À´ÖÎÀí¹¤¾ß £¬È»ºóÔÙÈκεط½Ê¹ÓÃÕâ¸ö¹¤¾ß¡£ÕâÖÖ×ö·¨¿ÉÄܻᵼÖ´úÂë¿É²âÊÔÐÔ¡¢¿ÉÀ©Õ¹ÐÔ¡¢¿Éά»¤ÐÔµÈÎÊÌâ £¬ÈÝÆ÷µÄ·ºÆð¿ÉÒÔ½â¾öÕâЩÎÊÌâ £¬ÈÝÆ÷½«¹¤¾ßʵÀýÍøÂçÖÎÀíÆðÀ´ £¬²¢ÇÒÒýÈëÁË IOC(¿ØÖÆ·´×ª)ÏàʶÀ´¾ÙÐй¤¾ßµÄÒÀÀµ×¢Èë £¬ÕâÑùÔڼܹ¹ÉϸüÆ«ÏòÓÚÃæÏò½Ó¿Ú,¾ßÓиüºÃµÄ¿É²âÊÔÐÔ¡¢¿ÉÀ©Õ¹ÐÔ¡¢¿Éά»¤ÐÔµÈÓŵã¡£

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

Èý¡¢ÔõÑùʹÓÃThinkPHP5.1ÈÝÆ÷£¿

ÔÚThinkPHP 5.1ÖÐÈÝÆ÷±»ÆÕ±éʹÓà £¬¹ØÓÚʹÓÃÈÝÆ÷½¨É蹤¾ß £¬ÒÔ¼°ÒÀÀµ×¢ÈëµÄÀú³ÌÖÐ £¬ÕâÀï¾Ù¸öÀý×Ó £¬Èø÷ÈËÄܸüºÃµØÃ÷È·ÈÝÆ÷ÊÇÔõÑùÊÂÇéµÄ£º

ÔÚapplication/extraĿ¼ÖÐÌí¼ÓÒ»¸öÉèÖÃÎļþ £¬ÀýÈç container.php¡£

<?php return [
    'foo' => function () {
        return new \app\common\Foo();
    }
];

µÇ¼ºó¸´ÖÆ

ÔÚÐèҪʹÓà Foo ÀàµÄµØ·½ £¬Ê¹ÓÃÈÝÆ÷ÔÚÉèÖÃÖвéÕÒËü¡£

<?php namespace app\index\controller;

use think\App;
use think\facade\Container;

class Index
{
    protected $foo;

    public function __construct(App $app)
    {
        $this->foo = Container::get('foo');
    }

    public function index()
    {
        return $this-&gt;foo-&gt;bar();
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃÇÌí¼ÓÁËÒ»¸öÃûΪ “foo” µÄÏîÄ¿µ½ÈÝÆ÷ÖС£µ±ÐèҪʹÓà Foo Ààʱ £¬ÎÒÃÇ¿ÉÒÔÔÚÈÝÆ÷Öлá¼ûÕâ¸ö¹¤¾ß¡£

ÈÝÆ÷ʹµÃ´úÂë¸ü¾ß¿É¶ÁÐÔ¡¢¿É²âÊÔÐÔ¡¢¿ÉÀ©Õ¹ÐԺͿÉά»¤ÐÔ¡£Ê¹ÓÃÈÝÆ÷ £¬ÎÒÃÇ¿ÉÒÔÔ½·¢Àû±ãµØÖÎÀíºÍ×éÖ¯Ó¦ÓóÌÐòÖеŤ¾ß £¬Ò²Äܹ»ÇáËɵؾÙÐÐÒÀÀµ×¢Èë¡£

×ܽá

ÈÝÆ÷ÊÇÒ»ÏîÖ÷ÒªµÄÊÖÒÕ £¬¿ÉÒÔ×ÊÖúÎÒÃǽâ¾ö¹Å°åPHP¿ª·¢ÖеÄһЩÎÊÌ⡣ͨ¹ýʹÓÃÈÝÆ÷ £¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØ×éÖ¯ºÍÖÎÀí¹¤¾ß £¬²¢ÇÒ¹¹½¨¿É²âÊÔ¡¢¿ÉÀ©Õ¹ºÍ¿Éά»¤µÄÓ¦ÓóÌÐò¡£ÔÚThinkPHP 5.1ÖÐ £¬ÈÝÆ÷±»ÆÕ±éʹÓà £¬²¢ÇÒ¿ÉÒÔÇáËɵؾÙÐÐÒÀÀµ×¢Èë¡£ÒÔÉÏÊÇÒ»¸ö²»Ì«ÉîÈëµÄÈÝÆ÷°¸Àý £¬¶øÔÚÏÖʵӦÓÃÖÐ £¬Ë¼Á¿µ½ÏµÍ³¼Ü¹¹»¯¡¢ÓªÒµÂß¼­»¯µÄÐèÒª £¬Ê¹ÓøüÓÅÃÀµÄ±àÂëÀ´¾ÙÐÐÈÝÆ÷µÄÓ¦Óá£

ÒÔÉϾÍÊÇÔõÑùʹÓÃThinkPHP 5.1µÄÈÝÆ÷µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ