laravel ÊÓͼ¼äÌøת
laravelÊÇÒ»¿îÊ¢ÐеÄphp¿ò¼Ü£¬¾ßÓпÉÀ©Õ¹¡¢ÎÞа¡¢Çå¾²µÈÌØÕ÷¡£ÔÚlaravel¿ò¼ÜÖУ¬ÊÓͼÊÇwebÓ¦ÓóÌÐòÖзºÆðÊý¾ÝµÄÒ»ÖÖ·½·¨¡£ÊÓͼÓÃÓÚÈ¡»ØºÍչʾÊý¾Ý£¬ÒÔ¼°ÔÊÐíÓû§¾ÙÐн»»¥²Ù×÷¡£
ÔÚLaravelÓ¦ÓóÌÐòÖУ¬Í¨³£»áÓÐÐí¶à²î±ðµÄÊÓͼ¡£ÕâЩÊÓͼ¿ÉÄÜÊÇÒ³ÃæÖ®¼äµÄÇл»»òÕßÒ»¸öÊÓͼÉϵIJî±ð״̬¡£Òò´Ë£¬ÊÓͼ֮¼äµÄÌøתÊÇLaravel½¹µã¿ª·¢ÕßÐèÒª½â¾öµÄÒ»¸öÎÊÌâ¡£
±¾ÎĽ«ÏÈÈÝLaravelÖÐÊÓͼ¼äÌøתµÄʵÏÖÒªÁì¡£
Ò»¡¢Ê¹Ó÷ÓÉʵÏÖÊÓͼÌøת
Laravel¿ò¼Üͨ¹ý·ÓÉ»úÖÆÀ´´¦ÀíÇëÇó¡£ÔÚÓ¦ÓÃÖУ¬Â·ÓÉÊÇURLºÍ´¦Àí¸ÃURLµÄ¿ØÖÆÆ÷Ö®¼äµÄÓ³Éä¹Øϵ¡£
ÒªÔÚLaravelÖÐʵÏÖÊÓͼÌøת£¬¿ÉÒÔ½ç˵һ¸ö·ÓÉ£¬²¢½«¸Ã·ÓÉÓëÒ»¸ö¿ØÖÆÆ÷ÒªÁì°ó¶¨¡£È»ºó£¬ÔÚ¿ØÖÆÆ÷ÒªÁìÖзµ»ØÒªÌøתµÄÊÓͼ¡£
ÀýÈ磬ÎÒÃÇ¿ÉÒÔ½«Â·ÓÉÖ¸Ïò¿ØÖÆÆ÷µÄindexÒªÁ죬¸ÃÒªÁì·µ»ØÓ¦ÓóÌÐòµÄÖ÷Ò³ÊÓͼ£º
Route::get('/', 'HomeController@index');
µÇ¼ºó¸´ÖÆ
ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵indexÒªÁ죺
class HomeController extends Controller { public function index() { return view('home'); } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂë¶ÎÖУ¬ÎÒÃÇŲÓÃviewº¯ÊýÀ´·µ»ØhomeÊÓͼ¡£viewº¯Êý½«¼ÓÔØresources/viewsĿ¼ÖеÄÊÓͼÎļþ¡£
¶þ¡¢Ê¹ÓÃÖض¨ÏòʵÏÖÊÓͼÌøת
Öض¨ÏòÊÇÒ»ÖÖ½«Óû§´ÓÄ¿½ñÒ³Ãæ·¢Ë͵½ÆäËûÒ³ÃæµÄÊÖÒÕ¡£ÔÚLaravelÖУ¬¿ÉÒÔͨ¹ýredirectÒªÁìÀ´ÊµÏÖÖض¨Ïò¡£
ÀýÈ磬ÈôÊÇÓû§ÒªÇó»á¼û²»±£´æµÄÒ³Ã棬¿ÉÒÔͨ¹ýÖض¨Ïò½«ËûÃÇÖض¨Ïòµ½Ö÷Ò³¡£ÔÚLaravelÖУ¬¿ÉÒÔͨ¹ýÒÔÏ´úÂë¶ÎʵÏÖÖض¨Ïò£º
Route::get('/404', function () { return redirect('/'); });
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂë¶ÎÖУ¬ÎÒÃǽç˵ÁËÒ»¸ö·ÓÉÀ´´¦Àí404¹ýʧ¡£µ±Óû§»á¼û²»±£´æµÄÒ³Ãæʱ£¬¸Ã·Óɽ«±»´¥·¢£¬²¢½«Óû§Öض¨Ïòµ½Ö÷Ò³¡£
Èý¡¢½¨Éè¹²ÏíÊÓͼ
ÔÚLaravelÓ¦ÓóÌÐòÖУ¬ÓÐʱÐèÒªÔÚ¶à¸öÊÓͼ֮¼ä¹²ÏíÊý¾Ý¡£Õâ¿ÉÒÔͨ¹ý¹²ÏíÊÓͼÀ´ÊµÏÖ¡£
¹²ÏíÊÓͼÊÇÒ»¸öÌØÊâµÄÊÓͼ£¬°üÀ¨ËùÓÐÓ¦ÓóÌÐòÖж¼ÐèҪʹÓõÄÊý¾Ý¡£ÕâЩÊý¾Ý¿ÉÒÔÊÇÉèÖÃÐÅÏ¢¡¢Óû§ÐÅÏ¢¡¢Ó¦ÓóÌÐòÊý¾ÝµÈ¡£
ÔÚLaravelÖУ¬¿ÉÒÔʹÓÃView::shareÒªÁìÀ´ÊµÏÖ¹²ÏíÊÓͼ¡£
ÀýÈ磬ÎÒÃÇ¿ÉÒÔ¹²ÏíÄ¿½ñµÇÈÎÃü»§µÄÐÅÏ¢¡£ÔÚAppServiceProviderÖÐÌí¼ÓÒÔÏ´úÂ룺
public function boot() { View::share('user', Auth::user()); }
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂë¶ÎÖУ¬ÎÒÃÇͨ¹ýAuth::user()ÒªÁì»ñÈ¡µÇÈÎÃü»§µÄÐÅÏ¢£¬²¢½«Æä´æ´¢ÔÚ$user±äÁ¿ÖС£È»ºó£¬Ê¹ÓÃView::shareÒªÁ콫¸Ã±äÁ¿¹²Ïíµ½ËùÓÐÊÓͼÖС£ÔÚËùÓÐÊÓͼÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý»á¼û$user±äÁ¿À´»á¼ûµÇÈÎÃü»§µÄÐÅÏ¢¡£
×ܽá
±¾ÎÄÏÈÈÝÁËLaravelÖÐÊÓͼ¼äÌøתµÄʵÏÖÒªÁì¡£ÎÒÃÇ¿ÉÒÔʹÓ÷ÓÉ¡¢Öض¨ÏòºÍ¹²ÏíÊÓͼÀ´ÊµÏÖÊÓͼ֮¼äµÄÌøתºÍÊý¾Ý¹²Ïí¡£
LaravelÊÇÒ»¸ö¹¦Ð§¸»ºñ¡¢ÎÞаµÄPHP¿ò¼Ü£¬¿ÉÒÔ×ÊÖúÎÒÃǹ¹½¨¸ßЧ¡¢¿ÉÀ©Õ¹µÄWebÓ¦ÓóÌÐò¡£ÊìÁ·ÕÆÎÕLaravel¿ò¼ÜÊÇWeb¿ª·¢Ö°Ô±µÄ±Ø±¸ÊÖÒÕ¡£
ÒÔÉϾÍÊÇlaravel ÊÓͼ¼äÌøתµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡