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

laravel5»ñÈ¡¿ØÖÆÆ÷ÒªÁì

ÔÚ laravel 5 ÖУ¬»ñÈ¡¿ØÖÆÆ÷ÒªÁìÊÇÒ»¸ö·Ç³£»ù±¾¶øÓÖ³£ÓõIJÙ×÷¡£ÔÚijЩ³¡¾°Ï£¬ÎÒÃÇ¿ÉÄÜÐèÒª»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷Ö´ÐеÄÒªÁìÃû³Æ¡£ÄÇô£¬ÔÚ laravel 5 ÖУ¬ÔõÑù»ñÈ¡¿ØÖÆÆ÷ÒªÁìÄØ£¿½ÓÏÂÀ´£¬ÈÃÎÒÃÇÒ»ÆðÀ´ÏàʶһÏ¡£

1¡¢$route ¹¤¾ß

ÔÚ Laravel 5 ÖУ¬$route ¹¤¾ßÉúÑÄÁËÄ¿½ñÕýÔÚÖ´ÐпØÖÆÆ÷µÄ·ÓÉÐÅÏ¢¡£Õâ¸ö¹¤¾ß°üÀ¨ÁËÇëÇóµÄ URI¡¢ÇëÇóÒªÁìÒÔ¼°Â·ÓɲÎÊýµÈ¡£ÈôÊÇÒª»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷µÄÒªÁìÃû£¬¿ÉÒÔͨ¹ý $route ¹¤¾ßµÄ ¡°getActionName¡± ÒªÁìÀ´»ñÈ¡¡£

/**
»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷ÒªÁìÃû³Æ
**/
public function getCurrentMethodName() {
    $route = Route::getCurrentRoute();
    $action = $route->getActionName();
    $fragments = explode('@', $action);
    $method = end($fragments);
    return $method;
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏ´úÂëÖУ¬ÎÒÃÇÊ×ÏÈͨ¹ý Route::getCurrentRoute() ÒªÁì»ñÈ¡Ä¿½ñµÄ·Óɹ¤¾ß£¬È»ºóʹÓà $route ¹¤¾ßµÄ ¡°getActionName¡± ÒªÁìÀ´»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷ÒªÁìµÄÍêÕû·¾¶£¬ÀýÈç ¡°AppHttpControllersTestController@index¡±¡£½Ó×Å£¬ÎÒÃÇʹÓà explode() º¯Êý½ØÈ¡³öÒªÁìÃû³Æ²¿·Ö£¬²¢Ê¹Óà end() º¯Êý»ñÈ¡Êý×éµÄ×îºóÒ»¸öÔªËØ£¬¼´¿ØÖÆÆ÷µÄÒªÁìÃû¡£×îºó£¬½«ÒªÁìÃû·µ»Ø¼´¿É¡£

2¡¢·´Éä

³ýÁËʹÓà $route ¹¤¾ßÍ⣬ÎÒÃÇ»¹¿ÉÒÔͨ¹ý PHP ·´Éä»úÖÆÀ´»ñÈ¡¿ØÖÆÆ÷ÒªÁì¡£PHP ·´Éä»úÖÆÌṩÁËÒ»¸öÀà ReflectionClass£¬¿ÉÓÃÓÚ»ñÈ¡ÀàµÄÏà¹ØÐÅÏ¢£¬°üÀ¨ÒªÁì¡¢ÊôÐÔ¡¢³£Á¿µÈ¡£Í¨¹ý ReflectionClass£¬ÎÒÃÇ¿ÉÒÔ»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷µÄÒªÁìÃû³Æ¡£

/**
»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷ÒªÁìÃû³Æ
**/
public function getCurrentMethodName() {
    $controller = Route::current()->getController();
    $reflection = new ReflectionClass($controller);
    $method = $reflection->getMethod(Route::currentRouteAction());
    return $method->name;
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏ´úÂëÖУ¬ÎÒÃÇÊ×ÏÈ»ñÈ¡Ä¿½ñ¿ØÖÆÆ÷µÄʵÀý¹¤¾ß£¬È»ºóʹÓà ReflectionClass Àà»ñÈ¡¸ÃʵÀý¹¤¾ßµÄ·´ÉäÐÅÏ¢¡£½Ó×Å£¬Í¨¹ý·´ÉäʵÀýµÄ getMethod() ÒªÁì»ñÈ¡Ä¿½ñÖ´ÐеÄÒªÁì¡£×îºó£¬Ê¹Ó÷´ÉäÒªÁìµÄ name ÊôÐÔ»ñÈ¡ÒªÁìÃû³Æ²¢·µ»Ø¼´¿É¡£

×ܽá

ÒÔÉϾÍÊÇÔÚ Laravel 5 ÖлñÈ¡¿ØÖÆÆ÷ÒªÁìµÄÁ½ÖÖÒªÁì¡£ÎÞÂÛÊÇÄÄÖÖ·½·¨£¬¶¼»áΪÎÒÃÇÌṩ·Ç³£¿ì½Ý¡¢Àû±ãµÄ²Ù×÷·½·¨£¬ÈÃÎÒÃǸüºÃµØÕÆ¿Ø¿ØÖÆÆ÷µÄÖ´ÐÐÇéÐΡ£ÈôÊÇÄã¶Ô Laravel 5 µÄ¿ª·¢ÓÐËùÒÉÎÊ»òÕßÐèҪѧϰ¸ü¶àÓÐ¹Ø Laravel 5 µÄÄÚÈÝ£¬ÇëÉó²é¹Ù·½Îĵµ»òÕ߽̳Ì¡£ÕÆÎÕ Laravel 5 ¿ª·¢ÄÜÁ¦£¬½«ÖúÄãÔÚ Web ¿ª·¢ÁìÓòÖÐѸËÙ»ñµÃÓÅÊÆ¡£

ÒÔÉϾÍÊÇlaravel5»ñÈ¡¿ØÖÆÆ÷ÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ