×ðÁú¿­Ê±

laravel ÒªÁìÄÚŲÓÃ

laravelÊÇÒ»ÖÖÇ¿Ê¢¶ø±ã½ÝµÄphp¿ò¼Ü £¬Ðí¶à¿ª·¢Õ߶¼Ï²»¶Ê¹ÓÃËüÀ´½¨ÉèÖÖÖÖÓ¦ÓóÌÐò¡£ÔÚÕâЩӦÓóÌÐòÖÐ £¬¿ª·¢Õßͨ³£ÐèҪŲÓòî±ðµÄÒªÁì²Å»ªÍê³ÉʹÃü¡£¿ÉÊÇ £¬ÈôÊÇ¿ª·¢ÕßÐèÒªÔÚÒ»¸öÒªÁìÄÚ²¿Å²ÓÃÁíÒ»¸öÒªÁì £¬Ó¦¸ÃÔõÑùʵÏÖ£¿±¾ÎĽ«ÎªÄúÏÈÈÝÔÚlaravelÖÐÒªÁìÄÚŲÓõļ¼ÇɺÍÒªÁì¡£

׼ȷŲÓÃÒªÁìµÄÓï·¨

ÔÚLaravelÖÐ £¬ÒªÁìµÄŲÓ÷½·¨ÓëPHPµÄͨÀýÓï·¨ÓÐЩ²î±ð¡£ÔÚÒ»¸öÒªÁìÄÚ²¿Å²ÓÃÁíÒ»¸öÒªÁìʱ £¬ÄúÐèÒª×ñÕÕÒÔÏÂÓï·¨£º

$this->methodName($parameter);

µÇ¼ºó¸´ÖÆ

Çë²Î¿¼ÏÂÃæµÄʾÀý£º

class Example {
  public function firstMethod($parameter) {
      // logic here
      $this->secondMethod($parameter);
  }

  public function secondMethod($parameter) {
      // logic here
  }
}

µÇ¼ºó¸´ÖÆ

ÈçÄúËù¼û £¬ÒªÔÚÒªÁìÄÚŲÓÃÁíÒ»¸öÒªÁì £¬ÄúÐèҪʹÓÔ$this”Òªº¦×Ö £¬ºó¸úŲÓõÄÒªÁìÃû³ÆºÍ²ÎÊý¡£ÊǵÄ £¬Äú¿ÉÒÔÏñÔÚͨÀýPHPÖÐÒ»ÑùÖ±½ÓŲÓøÃÒªÁì £¬¿ÉÊÇʹÓÃÕâ¸öÓï·¨ £¬½«×ÊÖúÄúÃ÷È·±íÊöËüÊÇÒ»¸öÀàÄÚÒªÁì £¬Ò×ÓÚ´úÂëÔĶÁ¡£

´¦Öóͷ£Å²ÓÃÀú³ÌÖеÄÒì³£

ÒªÁìÄÚŲÓÃÔÚijЩÇéÐÎÏ¿ÉÄÜ»áÒý·¢Òì³£¡£ÀýÈç £¬ÔÚŲÓÃÒªÁì֮ǰ £¬±ØÐèÈ·±£¹¤¾ßÒѾ­±»ÊµÀý»¯¡£ÈôÊÇÄúÕýÔÚŲÓÃijЩÉæ¼°»á¼ûÊôÐÔ»òÒªÁìµÄʵÀýÒªÁì £¬¶ø¸ÃʵÀýÉÐ佨Éè £¬¿ª·¢Õßͨ³£»áÓöµ½Ò»¸ö”ÖÂÃü¹ýʧ”¡£

ΪÁË×èÖ¹ÕâÖÖÇéÐÎ £¬Äú¿ÉÒÔʹÓÃÌõ¼þÓï¾ä»òtry catch¿éÀ´´¦Öóͷ£Å²ÓÃʱ´úµÄÒì³£¡£ÕâÑù £¬ÈôÊÇÄúÔÚŲÓÃÒªÁì֮ǰ¼ì²éµ½ÊµÀýÊÇ·ñ±£´æ £¬Ôò¿ÉÒÔ×èÖ¹ÕâЩÒì³£¡£ÒÔÏÂÊÇʹÓÃÌõ¼þÓï¾äµÄʾÀý£º

class Example {
  public function firstMethod($parameter) {
      if ($this->instance) {
          $this->secondMethod($parameter);
      }
  }

  public function secondMethod($parameter) {
      // logic here
  }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖÐ £¬ÎÒÃǼì²éÁËʵÀýÊÇ·ñ±£´æ £¬ÈôÊDZ£´æ £¬ÔòŲÓõڶþ¸öÒªÁì¡£ÈôÊÇʵÀý²»±£´æ £¬ÄÇô¾Í²»»áÓÐŲÓñ¬·¢ £¬Ò²¾Í²»»áÓÐÒì³£ÁË¡£

ÒÔÏÂÊÇʹÓÃtry catch¿éµÄÁíÒ»¸öʾÀý£º

class Example {
  public function firstMethod($parameter) {
      try {
          $this->secondMethod($parameter);
      } catch (Exception $e) { 
           // handle exception              
      }
  }

  public function secondMethod($parameter) {
      // logic here
  }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖÐ £¬ÎÒÃÇʹÓÃÁËtry catch¿é°ü×°ÒªÁìŲÓá£ÈôÊÇÔÚŲÓÃÀú³ÌÖÐÓöµ½ÁËÒì³£ £¬ÎÒÃÇ¿ÉÒÔÔÚcatch¿éÖⶻñ¸ÃÒì³£¡£ÔÚ´ËÇéÐÎÏ £¬ÎÒÃÇ¿ÉÒÔÖ´ÐÐ×Ô½ç˵µÄÒì³£´¦Öóͷ£Âß¼­ £¬²¢×îÖÕÖØÐÂÅ׳öÒì³£»ò·µ»ØÆäËûÖµ¡£

ÔõÑùÐÂÔöÒÀÀµ×¢Èë

ÒÀÀµ×¢ÈëÊÇÒ»ÖÖÉè¼Æģʽ £¬Ö§³Ö¶¯Ì¬¸ü¸ÄÀàÓëÀàÖ®¼äµÄÒÀÀµ¹Øϵ £¬¿ÉÒÔÓÃÓÚ¼ò»¯´úÂëºÍÌá¸ß¿ÉÖØÓÃÐÔ¡£ÔÚLaravelÖÐ £¬Äú¿ÉÒÔʹÓÃÒÀÀµ×¢ÈëÈÝÆ÷À´ÔöÌíÒÀÀµ×¢Èë¡£

ÒÀÀµ×¢ÈëÈÝÆ÷ÊÇÒ»¸öÈ«¾ÖµÄÈÝÆ÷ £¬´æ´¢ÀàʵÀý £¬²¢ÈÏÕæÆÊÎöÕâЩʵÀýµÄÒÀÀµÏî¡£Äú¿ÉÒÔʹÓÃÈÝÆ÷À´½¨ÉèʵÀý £¬½«ÊµÀý·ÖÅɸøÀàÊôÐÔ»òÔÚÒªÁìŲÓÃÖÐʹÓá£

ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄʾÀý£º

class Example {

  protected $dependency;

  public function __construct(Dependency $dependency) {
      $this->dependency = $dependency;
  }

  public function firstMethod() {
      $this->dependency->doSomething();
  }
}

$dependencyInstance = new Dependency;

$exampleInstance = new Example($dependencyInstance);
$exampleInstance->firstMethod();

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖÐ £¬ÎÒÃǽ¨ÉèÁËÒ»¸öÃûΪ”Example”µÄÀà £¬²¢ÏòËüµÄ½á¹¹Æ÷×¢ÈëÁËÒ»¸öÒÀÀµÏî”Dependency”¡£È»ºó £¬ÎÒÃǽ¨ÉèÒ»¸ö”Dependency”ʵÀý £¬²¢½«Ëü·ÖÅɸø”Example”ÀàµÄÒ»¸öÊôÐÔ¡£×îºó £¬ÎÒÃÇŲÓÔExample”µÄ”firstMethod”ÒªÁì £¬ËüÓÖŲÓÃÁË”Dependency”µÄÒ»¸öÒªÁì¡£

×ܽá

ÒªÁìÄÚŲÓÃÔÚ¿ª·¢Àú³ÌÖÐÊÇÒ»¸ö³£¼ûµÄÐèÇó¡£ÕâÖÖÒªÁì¿ÉÒÔïÔÌ­´úÂëÖØ´óÐÔ £¬²¢Ìá¸ß´úÂëµÄ¿É¶ÁÐÔ¡£Í¨¹ý×ñÕÕ׼ȷµÄÓï·¨Ô¼¶¨ £¬ÔÚ´úÂëÖд¦Öóͷ£Òì³£ £¬Ê¹ÓÃÒÀÀµ×¢ÈëÈÝÆ÷±ê¼ÇÒÀÀµ £¬Äú¿ÉÒÔ¸üºÃµØʹÓÃLaravel¿ò¼ÜµÄÄÜÁ¦¡£´Ó¶ø¸üÓÐÓõع¹½¨ÓÅÖʵÄÓ¦ÓóÌÐò¡£

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿