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

ʹÓÃlaravelÀ´´î½¨php

Ëæ×Å»¥ÁªÍøÊÖÒյĿìËÙÉú³¤ £¬webÓ¦ÓóÌÐòµÄÐèÇóÒ²Ô½À´Ô½¸ß¡£¶ø×÷Ϊ»¥ÁªÍøÌìÏÂÖÐ×î³£Óõıà³ÌÓïÑÔ £¬phpµÄʹÓùæÄ£Ò²×ãÒÔϯ¾íwebÓ¦ÓóÌÐòµÄ¾ø´ó²¿·Ö¡£¶ølaravel¿ò¼ÜÔòÊÇphp¿ª·¢Õß½¨ÉèÔ½·¢¸ßЧµÄwebÓ¦ÓóÌÐòµÄ±Ø±¸¹¤¾ßÖ®Ò»¡£ÔÚ´ËÎÄÕÂÖÐ £¬ÎÒÃǽ«Ì½ÌÖÔõÑùʹÓÃlaravel¿ò¼ÜÀ´´î½¨¸ßÖÊÁ¿µÄwebÓ¦ÓóÌÐò¡£

Ò»¡¢Laravel¿ò¼Ü¼ò½é

LaravelÊÇÒ»¸ö¿ªÔ´µÄPHP Web¿ò¼Ü £¬ËüµÄ³õʼ°æ±¾Ðû²¼ÓÚ2011Äê¡£Laravel¿ò¼ÜÓÃÓÚ¿ª·¢WebÓ¦ÓóÌÐò £¬ÌØÊâÊÇMVCģʽ£¨Model-View-Controller£©¹¹¼ÜϵÄWebÓ¦ÓóÌÐò £¬ÒÔ¼°RESTful API¡£Laravel¿ò¼ÜÊÇÒ»¸öÃâ·ÑµÄ¿ò¼Ü £¬²¢»ùÓÚMITÔÊÐíÖ¤¿ªÔ´¡£

¶þ¡¢Laravel¿ò¼ÜµÄÌØÕ÷

1¡¢¾«Á·ÎÞа

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

Laravel¿ò¼Ü¾ßÓкܺõÄÎÞаÐԺ;«Á·ÐÔ £¬ËüÓÐÒ»¸öºÜÊǼòÆÓ¶øÇå½àµÄ¿ò¼Ü½á¹¹ £¬²¢ÇÒÒ×ÓÚʹÓúÍѧϰ¡£¿ÉÒÔͨ¹ýComposerÀ´ÔöÌí»òɾ³ýLaravelµÄ¹¦Ð§Ä£¿é £¬ÈÃLaravel¿ò¼ÜÔ½·¢ÎÞа¡£

2¡¢Â·ÓÉϵͳ

Laravel¿ò¼ÜʹÓÃÒ»¸öÇ¿Ê¢µÄ·ÓÉϵͳ £¬¿ÉÒÔÇáËɵؽç˵ӦÓóÌÐòµÄ·ÓÉ¡£½ç˵·ÓÉÊǺÜÊÇÀû±ã £¬¿ÉÒÔʹÓÃRESTful APIÆøÑæÆøÑæµÄ·ÓÉ £¬Í¬Ê±Ò²Ö§³Ö¶àÖÐÑë¼þºÍÇëÇó²ÎÊý £¬¿ÉÒÔÖª×ã²î±ðµÄÐèÇó¡£

3¡¢Êý¾ÝǨáã

Laravel¿ò¼ÜÌṩÁËÒ»¸öºÜÊÇÀû±ãµÄÊý¾ÝǨá㹤¾ß £¬¿ÉÒÔÔÚ¿ª·¢Àú³ÌÖÐÇáËɵش¦ÀíÊý¾Ý¿â±íµÄ½¨Éè¡¢Ð޸ĺÍɾ³ýµÈ²Ù×÷¡£²¢ÇÒÕâЩ²Ù×÷ÊÇ¿É°æ±¾¿ØÖÆµÄ £¬Ê¹µÃÍŶӿª·¢Ô½·¢Ë³³©¡£

4¡¢ORM

Laravel¿ò¼ÜʹÓÃEloquentÀ´ÊµÏÖ¹¤¾ß¹ØϵӳÉ䣨ORM£© £¬¿ÉÒÔÉÁ¿ª·¢ÕßÇáËɵØÓëÊý¾Ý¿â¾ÙÐн»»¥ £¬¶ø²»±Øµ£ÐÄSQLÓï¾äµÄÖØ´óºÍ·±Ëö¡£³ýÁËEloquent £¬Laravel¿ò¼Ü»¹Ö§³ÖÀàËÆDoctrineºÍPropelµÄORM½â¾ö¼Æ»®¡£

5¡¢BladeÄ£°åÒýÇæ

Laravel¿ò¼ÜʹÓÃBladeÄ£°åÒýÇæ £¬¿ÉÒÔÇáËɵؽ«Êý¾Ý×¢Èëµ½ÊÓͼÖÐ £¬Í¬Ê±Ò²Ö§³Ö½á¹¹¡¢Ìõ¼þºÍÑ­»·µÈ³£¼ûµÄÄ£°åÓï·¨¡£BladeÄ£°åÒýÇæºÜÊÇÇ¿Ê¢ £¬¿ÉÊÇÒ²ºÜÊÇÒ×ÓÚʹÓá£

Èý¡¢Ê¹ÓÃLaravel¿ò¼ÜÀ´´î½¨WebÓ¦ÓóÌÐò

ÏÂÃæ £¬ÎÒÃǽ«´ÓÒÔϼ¸¸ö·½ÃæÀ´ËµÃ÷ÔõÑùʹÓÃLaravel¿ò¼ÜÀ´´î½¨WebÓ¦ÓóÌÐò¡£

1¡¢×°ÖÃLaravel¿ò¼Ü

×°ÖÃLaravel¿ò¼ÜºÜÊǼòÆÓ £¬¿ÉÒÔͨ¹ýʹÓÃComposer £¬Ö±½Ó´ÓÏÂÁîÐÐ×°ÖÃLaravel¡£¿ÉÒԲο¼ÒÔÏÂÏÂÁ

composer create-project –prefer-dist laravel/laravel project_name

Õ⽫´ÓPackagistÉÏ×Ô¶¯ÏÂÔز¢×°ÖÃ×îа汾µÄLaravel¿ò¼Ü¡£

2¡¢½¨Éè»ù±¾Â·ÓÉ

ÔÚLaravel¿ò¼ÜÖÐ £¬Â·Óɱ»½ç˵ÔÚroutes/web.phpÎļþÖС£¿ÉÒÔÔÚ¸ÃÎļþÖмÓÈëÒÔÏ´úÂ룺

Route::get(‘/’, function () { return view(‘welcome’); });

Õ⽫»á½ç˵һ¸öGETÇëÇóµÄ»ù±¾Â·ÓÉ £¬Ö¸Ïò¸ù·¾¶´¦ £¬²¢ÇÒ·µ»ØwelcomeÊÓͼ¡£ÊÓͼ¿ÉÒÔÔÚresources/viewsĿ¼ÏÂÃæ £¬½¨ÉèÒ»¸öwelcome.blade.phpÎĵµ¼´¿É¡£

3¡¢½¨Éè¿ØÖÆÆ÷

ÔÚLaravel¿ò¼ÜÖÐ £¬¿ØÖÆÆ÷ÈÏÕæ´¦ÀíËùÓеÄÓªÒµÂß¼­¡£¿ÉÒÔʹÓÃArtisan¹¤¾ßÀ´½¨ÉèÒ»¸ö¿ØÖÆÆ÷ £¬¿ÉÒԲο¼ÒÔÏÂÏÂÁ

php artisan make:controller UserController

Õ⽫½¨ÉèÒ»¸öÃûΪUserControllerµÄ¿ØÖÆÆ÷ £¬ÔÚapp/Http/ControllersĿ¼ÏÂÃæ¡£

ÏÖÔÚ £¬¿ÉÒÔÔÚUserControllerÖнç˵һЩҪÁìÀ´´¦Àí·ÓÉ £¬ºÃ±È£º

public function index() { return view(‘users.show’, [‘name’ => ‘Taylor’]); }

ÕâÀïÎÒÃǽç˵ÁËÒ»¸öÃûΪindexµÄÒªÁì £¬·µ»ØÁËÒ»¸öÃûΪusers.showµÄÊÓͼ £¬²¢ÇÒ´«ÈëÁËÒ»¸ö±äÁ¿name¡£

4¡¢½ç˵ÊÓͼ

ÔÚLaravel¿ò¼ÜÖÐ £¬ÊÓͼÎļþ¿ÉÒÔ´æ·ÅÔÚresources/viewsĿ¼ÏÂÃæ¡£ÆäÖÐ £¬ÊÓͼÎļþµÄÀ©Õ¹ÃûΪ.blade.php¡£

ÀýÈç £¬ÔÚresources/views/users/show.blade.phpÎļþÖмÓÈëÒÔÏ´úÂ룺

@yield(‘title’) @yield(‘content’)

ÕâÀïÎÒÃǽç˵ÁËÒ»¸ö»ù±¾µÄHTMLÄ£°å £¬²¢ÇÒʹÓÃÁËBladeÄ£°åÒýÇæµÄ@yieldÖ¸Áî £¬½ç˵ÁËtitleºÍcontentÁ½¸öÇøÓò¡£ÕâÑù £¬ÔÚÏêϸµÄÊÓͼÎļþÖпÉÒÔ¼ÌÐø¸Ã»ù±¾Ä£°å £¬½ç˵ÏêϸµÄÄÚÈÝ¡£

ÀýÈç £¬ÔÚresources/views/users/index.blade.phpÎļþÖпÉÒÔ¼ÓÈëÒÔÏ´úÂ룺

@extends(‘users.show’) @section(‘title’, ‘Óû§Áбí’) @section(‘content’)

Óû§Áбí

Taylor

Dayle

@endsection

ÕâÀïÎÒÃÇʹÓÃÁË@extendsÖ¸ÁîÀ´¼ÌÐøusers.showÊÓͼ £¬²¢ÇÒʹÓÃ@sectionÖ¸ÁîÀ´½ç˵ÁË×Ô¼ºµÄtitleºÍcontentÇøÓòÄÚÈÝ¡£ÆäÖÐ £¬contentÇøÓòÖаüÀ¨ÁËÒ»¸öulÁбí £¬ÓÃÓÚչʾÏêϸµÄÓû§ÐÅÏ¢¡£

5¡¢Ê¹ÓÃORMÖÎÀíÊý¾Ý¿â

ÔÚLaravel¿ò¼ÜÖÐ £¬¿ÉÒÔʹÓÃORMÀ´ÖÎÀíÊý¾Ý¿â¡£ÀýÈç £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸öUserÄ£×Ó£º

php artisan make:model User

Õ⽫»áÔÚappĿ¼Ï½¨ÉèÒ»¸öÃûΪUserµÄPHPÎļþ £¬¿ÉÒÔÔÚ¸ÃÎļþÖнç˵¸ÃÄ£×ӺͱíÖ®¼äµÄÓ³Éä¹Øϵ¡£

ÔÚLaravel¿ò¼ÜÖÐ £¬¿ÉÒÔʹÓÃEloquentÄ£×ÓÀ´ºÍÊý¾Ý¿âʵÏÖ½»»¥¡£ÀýÈ磺

// ÅÌÎÊËùÓÐÓû§ $users = AppUser::all(); // ÅÌÎÊÃû³ÆΪTaylorµÄÓû§ $user = AppUser::where(‘name’, ‘Taylor’)->first();

ÔÚÕâÑùµÄÅÌÎÊÖÐ £¬LaravelʹÓÃÒ»¸öºÜÊǾ«Á·ÇÒÒ×ÓÚÃ÷È·µÄAPIÀ´ÊµÏÖORM¡£Í¬Ê± £¬¿ÉÒÔʹÓøü¶àÖØ´óµÄÅÌÎʲÙ×÷ £¬ºÃ±ÈÁ´Ê½Å²ÓᢾۺϺÍÅþÁ¬µÈµÈ¡£

ËÄ¡¢½áÂÛ

ÔÚ±¾ÎÄÖÐ £¬ÎÒÃǼòÒªÏÈÈÝÁËLaravel¿ò¼Ü £¬²¢ÇÒ̽ÌÖÁËÔõÑùʹÓÃLaravel¿ò¼ÜÀ´´î½¨¸ßÖÊÁ¿µÄWebÓ¦ÓóÌÐò¡£Laravel¿ò¼ÜÊÇÒ»¸öÇ¿Ê¢ÇÒÒ×ÓÚʹÓõĿò¼Ü £¬ËüÓµÓÐÎÞаµÄ½á¹¹ºÍÇ¿Ê¢µÄ¹¦Ð§ £¬¿ÉÒÔÇáËɵØÖª×㿪·¢ÕßµÄÐèÇó¡£ÈôÊÇÄúÕýÔÚÑ°ÕÒÒ»¸ö¸ßЧµÄPHP Web¿ò¼ÜÀ´¼ÓËÙÄúµÄWebÓ¦ÓóÌÐòµÄ¿ª·¢Àú³Ì £¬ÄÇôLaravel¿ò¼ÜÒ»¶¨ÊÇÄúµÄ²»¶þ֮ѡ¡£

ÒÔÉϾÍÊÇʹÓÃlaravelÀ´´î½¨phpµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ