thinkphp ÔõôȥµôµÇ¼¹¦Ð§
ÔÚ¿ª·¢Àú³ÌÖУ¬ÎÒÃÇÓÐʱ¼äÐèҪȥµôµÇ¼¹¦Ð§£¬ºÃ±È²âÊԽ׶Σ¬ÐèÒª¿ìËÙ½øÈëǰ̨ҳÃæ¾ÙÐпª·¢²âÊÔ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ thinkphp ¿ò¼ÜÖÐÈ¥µôµÇ¼¹¦Ð§¡£
ɾ³ýµÇ¼Ïà¹Ø´úÂë
ÔÚ ThinkPHP ¿ò¼ÜÖУ¬µÇ¼¹¦Ð§Í¨³£ÓÉ¿ØÖÆÆ÷¡¢Ä£×Ó¡¢ÊÓͼÈý²¿·Ö´úÂë×é³É¡£ÎÒÃÇÐèҪɾ³ýÕâЩ´úÂ룬ÒÔÈ¥µôµÇ¼¹¦Ð§¡£
Ê×ÏÈ£¬·¿ª¿ØÖÆÆ÷Îļþ£¬ÕÒµ½ÓëµÇ¼Ïà¹ØµÄ´úÂ룬ֱ½Óɾ³ý¿ØÖÆÆ÷ÖеĵǼҪÁì¡£
Æä´Î£¬·¿ªÄ£×ÓÎļþ£¬ÕÒµ½ÓëµÇ¼Ïà¹ØµÄ´úÂ룬ɾ³ý¸Ã²¿·Ö´úÂë¡£ÈôÊÇÄúµÄÄ£×ÓÖÐûÓÐÏà¹Ø´úÂ룬ÔòÎÞÐè¸ü¸Ä¡£
×îºó£¬·¿ªÊÓͼÎļþ£¬ÕÒµ½ÓëµÇ¼Ïà¹ØµÄ´úÂ룬ɾ³ýµÇ¼½çÃæ¼°µÇ¼±íµ¥¡£ÈçÏÂͼ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ɾ³ýµÇ¼·ÓÉ
ÔÚ ThinkPHP ¿ò¼ÜÖУ¬Â·ÓÉÎļþ routes.php ½ç˵ÁË»á¼û¸÷¸öÒ³ÃæµÄ·¾¶£¬ÎÒÃÇÐèҪɾ³ýµÇ¼µÄ·ÓÉ£¬ÒÔÈ¥µôµÇ¼¹¦Ð§¡£
·¿ª routes.php Îļþ£¬ÕÒµ½µÇ¼Ïà¹ØµÄ·ÓÉ´úÂ룬ɾ³ý¸Ã²¿·Ö´úÂë¡£ÈçÏ£º
// µÇ¼Ïà¹Ø·ÓÉ Route::rule('login', 'admin/Login/login'); Route::rule('logout', 'admin/Login/logout'); Route::rule('verify', 'admin/Login/verify');
µÇ¼ºó¸´ÖÆ
ɾ³ýºóµÄ´úÂëÈçÏ£º
// µÇ¼Ïà¹Ø·ÓÉ // Route::rule('login', 'admin/Login/login'); // Route::rule('logout', 'admin/Login/logout'); // Route::rule('verify', 'admin/Login/verify');
µÇ¼ºó¸´ÖÆ
È¥µôÈÏÖ¤ÖÐÑë¼þ
ThinkPHP ¿ò¼ÜÖеÄÈÏÖ¤ÖÐÑë¼þ AuthMiddleware ÓÃÓÚÑéÖ¤Óû§Éí·Ý£¬ÎÒÃÇÐèҪȥµô¸ÃÖÐÑë¼þ£¬ÒÔÈ¥µôµÇ¼¹¦Ð§¡£
·¿ª middleware.php Îļþ£¬ÕÒµ½ÒÔÏ´úÂ룺
return [ 'AuthMiddleware' => app\middleware\AuthMiddleware::class, ];
µÇ¼ºó¸´ÖÆ
½«Æä¸ÄΪÒÔÏ´úÂë¼´¿ÉÈ¥µôÈÏÖ¤ÖÐÑë¼þ£º
return [ // 'AuthMiddleware' => app\middleware\AuthMiddleware::class, ];
µÇ¼ºó¸´ÖÆ
È¥µôµÇ¼ÑéÖ¤
ThinkPHP ¿ò¼ÜÖеÄÓû§ÈÏÖ¤¹¦Ð§Ö÷ÒªÓÉ Auth ÀàÌṩ£¬ÎÒÃÇÐèҪȥµô Auth Àà¶ÔµÇ¼µÄÑéÖ¤¡£
·¿ª config.php Îļþ£¬ÕÒµ½ÒÔÏ´úÂ룺
// Óû§ÈÏÖ¤ÉèÖà 'auth' => [ // µÇ¼ÑéÖ¤ 'login_scene' => 'login', 'admin_user_table' => 'admin_user', 'admin_auth_rule_table' => 'admin_auth_rule', 'admin_auth_rule_access_table' => 'admin_auth_rule_access', 'admin_auth_user_access_table' => 'admin_auth_user_access', ],
µÇ¼ºó¸´ÖÆ
ɾ³ýÆäÖÐµÄ ‘login_scene’ => ‘login’ £¬¼´¿ÉÈ¥µôµÇ¼ÑéÖ¤¡£
µ½´ËΪֹ£¬ÎÒÃÇÒѾÍê³ÉÁËÈ¥µôµÇ¼¹¦Ð§µÄ²Ù×÷¡£
×ܽá
±¾ÎÄÏÈÈÝÁËÔÚ ThinkPHP ¿ò¼ÜÖÐÈ¥µôµÇ¼¹¦Ð§µÄÒªÁ죬Ö÷Òª°üÀ¨É¾³ýµÇ¼Ïà¹Ø´úÂ롢ɾ³ýµÇ¼·ÓÉ¡¢È¥µôÈÏÖ¤ÖÐÑë¼þºÍÈ¥µôµÇ¼ÑéÖ¤¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ¿ÉÒÔƾ֤ÏêϸÐèÇó¾ÙÐÐÏìÓ¦µÄ²Ù×÷£¬ÒÔµÖ´ï¿ìËÙ¿ª·¢µÄÄ¿µÄ¡£
ÒÔÉϾÍÊÇthinkphp ÔõôȥµôµÇ¼¹¦Ð§µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡