laravel ÔöÌí·ÓÉÎļþ
laravelÊÇÒ»¸öÊ¢ÐеÄphp¿ò¼Ü£¬¾ßÓо«Á·ÓÅÃÀµÄÓï·¨ºÍÇ¿Ê¢µÄ¹¦Ð§¡£ÔÚʹÓÃlaravel¿ª·¢Ó¦ÓóÌÐòʱ£¬¾³£ÐèÒªÌí¼Ó×Ô½ç˵·ÓÉÀ´´¦Öóͷ£»á¼û²î±ðÒ³ÃæµÄÇëÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÏîÄ¿ÖÐÔöÌí×Ô½ç˵·ÓÉÎļþ£¬Àû±ã¿ª·¢Ö°Ô±ÖÎÀíºÍά»¤Â·ÓÉÐÅÏ¢¡£
н¨Â·ÓÉÎļþ
ÔÚLaravelÏîÄ¿µÄroutesĿ¼Ï£¬Í¨³£»áÓÐÒ»¸öweb.phpÎļþºÍapi.phpÎļþ¡£ÕâÁ½¸öÎļþ»®·ÖÓÃÓÚ½ç˵WebºÍAPI·ÓÉ¡£ÎÒÃÇ¿ÉÒÔÔÚÕâ¸öĿ¼ÏÂн¨Ò»¸öÃûΪcustom.phpµÄÎļþ£¬ÓÃÓÚ´æ·Å×Ô½ç˵·ÓÉ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÔÚÏÂÁîÐÐÖн¨ÉèÒ»¸öÐÂÎļþ£º
touch routes/custom.php
µÇ¼ºó¸´ÖÆ
ÉèÖ÷ÓÉÎļþ
·¿ªcustom.phpÎļþ£¬×îÏÈÉèÖÃ×Ô½ç˵·ÓÉ¡£Â·ÓÉ·ÖΪget¡¢post¡¢put¡¢deleteµÈÀàÐÍ£¬»®·Ö´¦Öóͷ£Óû§µÄÇëÇó¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÀý×Ó£¬ÓÃÓÚ´¦Öóͷ£GETÇëÇó»á¼ûÒ»¸ö×Ô½ç˵ҳÃ棺
Route::get('/custom-page', function () { return view('custom'); });
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬½ç˵ÁËÒ»¸öÃûΪcustom-pageµÄ·ÓÉ£¬¸Ã·ÓɵÄÏìÓ¦º¯Êý·µ»ØÁËÒ»¸öÃûΪcustomµÄÊÓͼ£¬ÓÃÓÚչʾ×Ô½ç˵ҳÃæ¡£ÕâÀïµÄÊÓͼÎļþÐèÒªÔÚresources/viewsĿ¼ÏÂÏȽ¨ÉèºÃ¡£
×¢²á·ÓÉÎļþ
ΪÁËÈÃLaravelÏîÄ¿Äܹ»Ê¶±ðºÍʹÓÃcustom.phpÎļþÖеÄ·ÓÉ£¬ÐèÒªÔÚÏîÄ¿ÖÐ×¢²á¸ÃÎļþ¡£¿ÉÒÔÔÚapp/Providers/RouteServiceProvider.phpÎļþÖеÄmapº¯ÊýÖÐÌí¼ÓÈçÏ´úÂ룺
protected function mapCustomRoutes() { Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/custom.php')); }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬½ç˵ÁËÒ»¸öÃûΪmapCustomRoutesµÄº¯Êý£¬ÓÃÓÚ×¢²á×Ô½ç˵·ÓÉÎļþ¡£Ôڸú¯ÊýÖÐʹÓÃgroupº¯Êý½«×Ô½ç˵·ÓÉÎļþ°ó¶¨µ½WebÖÐÐļþÏ£¬²¢Ö¸¶¨ÁË·ÓÉÎļþËù´¦µÄĿ¼·¾¶¡£
½ÓÏÂÀ´£¬ÔÚRouteServiceProvider.phpÎļþÖеÄmapº¯ÊýÖÐŲÓÃmapCustomRoutesº¯Êý¼´¿ÉÍê³É×Ô½ç˵·ÓɵÄ×¢²á£º
public function map() { $this->mapWebRoutes(); $this->mapApiRoutes(); $this->mapCustomRoutes(); // ×¢²á×Ô½ç˵·ÓÉÎļþ }
µÇ¼ºó¸´ÖÆ
²âÊÔ×Ô½ç˵·ÓÉ
Íê³É×Ô½ç˵·ÓÉÎļþµÄÉèÖúÍ×¢²áºó£¬¾Í¿ÉÒÔÔÚÏîÄ¿ÖвâÊÔ×Ô½ç˵·ÓÉÁË¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÆô¶¯LaravelÏîÄ¿£¬²¢ÔÚä¯ÀÀÆ÷Öлá¼ûhttp://localhost/custom-page£¬Éó²éÊÇ·ñÀֳɼÓÔØ×Ô½ç˵ҳÃ棺
php artisan serve
µÇ¼ºó¸´ÖÆ
×Ô½ç˵ҳÃæµÄ»á¿´·¨Ö·Îª£ºhttp://localhost/custom-page
×ܽá
ÒÔÉϾÍÊÇÔÚLaravelÏîÄ¿ÖÐÔöÌí×Ô½ç˵·ÓÉÎļþµÄ°ì·¨¡£Í¨¹ý½¨Éè×Ô½ç˵·ÓÉÎļþ£¬¿ÉÒÔ¸üºÃµØÖÎÀíºÍά»¤LaravelÓ¦ÓóÌÐòÖÐÖÚ¶àµÄ·ÓÉÐÅÏ¢¡£Í¬Ê±£¬Ò²Ê¹µÃ·ÓÉÂß¼Ô½·¢ÇåÎúºÍÒ×ÓÚ¿ª·¢Ö°Ô±Ã÷È·ºÍµ÷ÊÔ¡£
ÒÔÉϾÍÊÇlaravel ÔöÌí·ÓÉÎļþµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡