laravel¿ò¼ÜÁ÷³ÌÊÇʲô
laravel¿ò¼ÜÊÇÒ»¿î¹ãÊܽӴýµÄphp¿ò¼Ü£¬Æä¼òÆÓÒ×ÓᢸßЧ¿É¿¿¡¢¹¦Ð§Ç¿Ê¢µÈÓŵãÊܵ½ÁËÐí¶à¿ª·¢ÕßµÄÇàíù¡£ÔÚʹÓÃlaravel¿ò¼Ü¾ÙÐÐweb¿ª·¢Ê±£¬ÎÒÃÇÐèÒªÃ÷È·Æ俪·¢Á÷³Ì£¬°üÀ¨×°Öá¢Â·ÓÉ¡¢¿ØÖÆÆ÷¡¢Ä£×ÓºÍÊÓͼµÈ·½Ãæ¡£ÏÂÃæ¾ÍÀ´ÏêϸÏÈÈÝÒ»ÏÂlaravel¿ò¼ÜµÄÁ÷³Ì¡£
Ò»¡¢×°ÖÃ
Laravel¿ò¼ÜµÄ×°ÖúÜÊǼòÆÓ£¬Ö»ÐèÒªÔËÐÐÒÔÏÂÏÂÁî¼´¿É£º
composer create-project --prefer-dist laravel/laravel your-project-name
µÇ¼ºó¸´ÖÆ
ÆäÖÐyour-project-nameÌåÏÖÄãµÄÏîÄ¿Ãû³Æ¡£ÕâÌõÏÂÁî»á×Ô¶¯ÏÂÔز¢×°ÖÃ×îа汾µÄLaravel¿ò¼Ü¼°ÆäÒÀÀµ¿â£¬²¢½¨ÉèÒ»¸öÃûΪyour-project-nameµÄÏîÄ¿£¬×°ÖÃÍê³Éºó¼´¿Éͨ¹ý»á¼ûhttp://your-project-name/publicÀ´»á¼ûÄãµÄLaravelÓ¦Óá£
¶þ¡¢Â·ÓÉ
·ÓÉÊÇLaravel¿ò¼ÜµÄ½¹µãÖ®Ò»£¬Ëü½ç˵ÁËÇëÇóµÄURLºÍ¶ÔÓ¦µÄ´¦ÀíÒªÁì¡£ÔÚLaravelÖУ¬Â·Óɽç˵±£´æÁ½ÖÖ·½·¨£º¶¥¼¶Â·ÓɺͿØÖÆÆ÷·ÓÉ¡£
1¡¢¶¥¼¶Â·ÓÉ
¶¥¼¶Â·ÓɾÍÊÇÖ±½ÓÔÚroutes/web.phpÎļþÖнç˵·ÓÉ£¬ÆäÖаüÀ¨ÇëÇóÒªÁìºÍURLÒÔ¼°¶ÔÓ¦µÄ´¦ÀíÒªÁ죬ÀýÈ磺
Route::get('/', function () { return view('welcome'); });
µÇ¼ºó¸´ÖÆ
Õâ¸öÀý×ÓÖУ¬µ±Óû§»á¼ûÖ÷ҳʱ£¬»áÖ´ÐÐÒ»¸öÄäÃûº¯Êý£¬²¢·µ»ØÒ»¸öÃûΪwelcomeµÄÊÓͼ¡£
2¡¢¿ØÖÆÆ÷·ÓÉ
³ýÁËʹÓÃÄäÃûº¯Êý´¦Àí·ÓÉÍ⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÿØÖÆÆ÷À´´¦Àí·ÓÉ¡£Ê×ÏÈÐèÒª½ç˵һ¸ö¿ØÖÆÆ÷À࣬ÔÚ¿ØÖÆÆ÷ÀàÖнç˵һ¸öÒªÁìÀ´´¦Àí·ÓÉ£¬ÀýÈ磺
namespace App\Http\Controllers; use Illuminate\Http\Request; class UserController extends Controller { public function index() { return view('user.index'); } }
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÔÚroutes/web.phpÎļþÖÐʹÓÃÒÔÏ·½·¨½ç˵·ÓÉ£º
Route::get('/user', 'UserController@index');
µÇ¼ºó¸´ÖÆ
Õâ¸öÀý×ÓÖУ¬µ±Óû§»á¼û/userʱ£¬»áÖ´ÐÐUserController¿ØÖÆÆ÷µÄindexÒªÁ죬²¢·µ»ØÒ»¸öÃûΪuser.indexµÄÊÓͼ¡£
Èý¡¢¿ØÖÆÆ÷
¿ØÖÆÆ÷ÓÃÓÚ´¦Àí·ÓÉÇëÇ󣬲¢½«Êý¾Ýת´ï¸øÊÓͼ¾ÙÐÐչʾ¡£ÔÚLaravelÖУ¬Ò»¸ö¿ØÖÆÆ÷°üÀ¨¶à¸öÒªÁ죬ÿ¸öÒªÁìÓÃÀ´´¦Àí²î±ðµÄÇëÇó¡£ÎÒÃÇ¿ÉÒÔʹÓÃArtisanÏÂÁîÐй¤¾ßÀ´ÌìÉú¿ØÖÆÆ÷£¬ÀýÈ磺
php artisan make:controller UserController
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁî»áÔÚapp/Http/ControllersĿ¼ÏÂÌìÉúÒ»¸öÃûΪUserControllerµÄ¿ØÖÆÆ÷Àà¡£ÔÚÕâ¸ö¿ØÖÆÆ÷ÀàÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý¸ÃÀàµÄÒªÁìÀ´ÌìÉúÊý¾Ý²¢·µ»ØÊÓͼ¡£
ËÄ¡¢Ä£×Ó
Ä£×ÓÊÇLaravel¿ò¼ÜÖÐÅþÁ¬Êý¾Ý¿âµÄ½¹µã£¬Ëü¿ÉÒÔ×ÊÖúÎÒÃÇÔÚÊý¾Ý¿âÖÐÅÌÎÊÊý¾Ý²¢¾ÙÐвÙ×÷¡£ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃArtisanÏÂÁîÌìÉúÄ£×Ó£¬ÀýÈ磺
php artisan make:model User
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁî»áÔÚappĿ¼ÏÂÌìÉúÒ»¸öÃûΪUserµÄÄ£×ÓÀà¡£ÎÒÃÇ¿ÉÒÔʹÓÃÕâ¸öÄ£×ÓÀàÀ´ÅÌÎʺͲÙ×÷Êý¾Ý¿âÖеÄÊý¾Ý¡£
Îå¡¢ÊÓͼ
ÊÓͼÊÇLaravel¿ò¼ÜÖÐչʾÊý¾ÝµÄÖ÷Òª·½·¨£¬Ò²ÊÇÇ°¶Ë¿ª·¢Õß±ØÐèÕÆÎÕµÄÊÖÒÕ¡£ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃBladeÄ£°åÒýÇæÀ´ÌìÉúºÍäÖȾÊÓͼ¡£BladeÄ£°åÒýÇæÌṩÁËÐí¶àÀû±ãµÄÓï·¨×ÊÖúÎÒÃÇ¿ìËÙÌìÉúÒ³Ã棬ÀýÈ磺
nbsp;html> <title>@yield('title')</title> @section('sidebar') This is the master sidebar. @show <div> @yield('content') </div>
µÇ¼ºó¸´ÖÆ
Õâ¸öÀý×ÓÖУ¬@yieldÓÃÓÚ½ç˵һ¸öռλ·û£¬µ±ÆäËûÊÓͼ¼ÌÐøÕâ¸öÊÓͼʱ£¬¿ÉÒÔʹÓÃ@section½ç˵ÃûΪsidebarµÄռλ·û¡£ÔÚÆäËûÊÓͼÖÐʹÓÃ@parentÀ´Ìæ»»¸¸ÊÓͼÖеÄռλ·û¡£Ê¹ÓÃBladeÄ£°åÒýÇæ¿ÉÒÔʹÎÒÃÇ¿ìËÙÌìÉú²¢äÖȾÊÓͼ¡£
×ܽ᣺ ÒÔÉϾÍÊÇLaravel¿ò¼Ü¿ª·¢Á÷³ÌµÄ¼òÒªÏÈÈÝ£¬ÎÒÃÇ¿ÉÒÔƾ֤ÐèÒªÀ´Ñ¡ÔñºÍʹÓÃLaravelµÄ¸÷¸ö¹¤¾ßºÍÁ÷³Ì£¬¹¹½¨³öÔ½·¢Îȹ̺͸ßЧµÄWEBÓ¦Óá£
ÒÔÉϾÍÊÇlaravel¿ò¼ÜÁ÷³ÌÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡