Ïê½â Laravel µÄÔ´Âë
laravel ÊÇÒ»¿îÓÅÒìµÄ php web ¿ò¼Ü£¬±»ÆÕ±éÓ¦ÓÃÕßÐí¶à¿ª·¢ÏîÄ¿ÖС£laravel ¿ò¼ÜµÄÓÅÒìÌåÏÖ²»µ«ÔÚÆäÎÞаÐÔ¡¢Ò×ÓÃÐÔ¡¢Çå¾²ÐÔÉÏ£¬»¹ÔÚÓÚÆäÓµÓÐÍêÕûµÄÔ´Âë¡£²»µ«ÔÆÔÆ£¬laravel Ô´ÂëµÄ¿ª·ÅҲΪ¿í´ó¿ª·¢ÕßÌṩÁ˲ο¼ºÍѧϰµÄʱ»ú¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÓà laravel µÄÔ´Âë¡£
Ò»¡¢ÏÂÔØ Laravel Ô´Âë
ҪʹÓà Laravel Ô´Â룬Ê×ÏÈÐèÒªÏÂÔØÆä¹¹½¨Ô´ÂëµÄ¹¤¾ß£¬Composer¡£Composer ÊÇÒ»¿îÓÃÓÚ PHP ¿ª·¢µÄÒÀÀµÖÎÀíÆ÷¡£ÔÚ×°Öà Composer ºó£¬ÎÒÃǾͿÉÒÔʹÓà Composer ¾ÙÐÐ Laravel µÄÔ´ÂëÏÂÔØ¡£
ÏÂÔØÔ´ÂëµÄÏÂÁîÈçÏ£º
composer create-project --prefer-dist laravel/laravel blog
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÏÂÁîÖУ¬blog ÊÇÄãÒª½¨ÉèµÄÏîÄ¿Ãû³Æ¡£´ýÔ´ÂëÏÂÔØÍê³Éºó£¬ÎÒÃǾͿÉÒÔ½øÈë Laravel ÏîÄ¿µÄÖ÷Ŀ¼¡£
¶þ¡¢Laravel Ô´ÂëµÄ»ù±¾½á¹¹
ÔÚ Laravel Ô´ÂëÖУ¬ÏîÄ¿µÄÖ÷Ŀ¼°üÀ¨¶à¸ö×ÓĿ¼ºÍÎļþ¡£ÕâЩ×ÓĿ¼ºÍÎļþµÄ×÷ÓÃÈçÏ£º
app£ºÕâÀï°üÀ¨ÁËÓ¦ÓóÌÐòµÄ»ù±¾´úÂ룬°üÀ¨¿ØÖÆÆ÷¡¢Ä£×Ó¡¢ÖÐÐļþµÈ¡£
bootstrap£º¸ÃĿ¼Ï°üÀ¨ÁË¿ò¼ÜµÄÖ¸µ¼Îļþ£¬°üÀ¨ÉèÖÃÎļþµÈ¡£
config£ºÕâ¸öĿ¼°üÀ¨ÁËÓ¦ÓóÌÐòµÄËùÓÐÉèÖÃÎļþ¡£
database£º´ËĿ¼°üÀ¨ÁËÓ¦ÓóÌÐòµÄËùÓÐÊý¾Ý¿âǨáãºÍÌî³ä¾ç±¾¡£
public£ºÕâ¸öĿ¼°üÀ¨ÁËÓ¦ÓóÌÐòµÄËùÓй«¹²Îļþ£¬°üÀ¨Í¼Ïñ¡¢JavaScript ºÍ CSS ´úÂë¡£
resources£ºÕâ¸öĿ¼°üÀ¨ÁËÓ¦ÓóÌÐòµÄËùÓÐ×ÊÔ´Îļþ£¬ÀýÈç Blade ÊÓͼ¡¢ÓïÑÔÎļþºÍ Sass ÎļþµÈ¡£
routes£º¸ÃĿ¼°üÀ¨ÁËÓ¦ÓóÌÐòµÄ»ù±¾Â·Óɽç˵¡£
storage£ºÕâ¸öĿ¼°üÀ¨ÁË´æ´¢Ó¦ÓóÌÐòÊý¾ÝµÄËùÓÐÎļþ£¬°üÀ¨ÈÕÖ¾¡¢»º´æºÍ±àÒëµÄ Blade Ä£°åµÈ¡£
tests£ºÕâ¸öĿ¼°üÀ¨ÁËÓ¦ÓóÌÐòµÄËùÓвâÊÔÎļþ¡£
vendor£º¸ÃĿ¼°üÀ¨ÁËÒÀÀµÓÚ Laravel µÄËùÓаüºÍ×é¼þ¡£
Èý¡¢Ê¹Óà Laravel µÄÔ´Âë
ÓÐÁË¶Ô Laravel Ô´Âë½á¹¹µÄ»ù±¾ÊìϤ£¬ÎÒÃǾͿÉÒÔʹÓÃÕâЩԴÂë×îÏÈÎÒÃǵÄÏîÄ¿ÁË¡£Ê×ÏÈ£¬ÎÒÃÇ¿ÉÒÔʹÓà Artisan ÏÂÁîÀ´ÌìÉúһЩ»ù±¾µÄ´úÂ룺
php artisan make:controller UserController
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁî¿ÉÒÔÌìÉúÒ»¸öÃûΪ UserController µÄ¿ØÖÆÆ÷¡£µ±ÎÒÃÇÐèÒªÔÚ¿ØÖÆÆ÷ÖÐÌí¼ÓһЩҪÁìʱ£¬ÎÒÃÇÖ»Ðè¼òÆÓµØÔÚ UserController ÖÐÔöÌíÒªÁì¼´¿É¡£ÀýÈ磬ÎÒÃÇÔÚ UserController ÖÐÔöÌíÁËÒ»¸ö index ÒªÁ죺
public function index() { return view('users.index'); }
µÇ¼ºó¸´ÖÆ
¸ÃÒªÌå»á·µ»ØÒ»¸öÃûΪ users.index µÄÊÓͼ¡£Óû§¿ÉÒÔÔÚÆäÖнç˵ģ°åÎļþ¡£ÀýÈ磬ÎÒÃÇÔÚ resources\views\users Ŀ¼ÏÂн¨ÁËÒ»¸ö index.blade.php Ä£°åÎļþ£º
@extends('layouts.app') @section('content') <div> <div> <div> Laravel </div> <div> <a>Documentation</a> <a>Laracasts</a> <a>News</a> <a>Forge</a> <a>GitHub</a> </div> </div> </div> @endsection
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÄ£°åÖУ¬ÎÒÃÇͨ¹ý @extends ºÍ @section Ö¸ÁîÀ´¼ÌÐøºÍäÖȾ½á¹¹¡£±ðµÄ£¬Óû§»¹¿ÉÒÔÔÚÄ£°åÖÐʹÓà Blade µÄÄ£°åÒýÇæÀ´¾ÙÐÐÊÓͼäÖȾ£¬°üÀ¨Ñ»·¡¢Ìõ¼þÓï¾äµÈ¡£
ËÄ¡¢½áÓï
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔõÑùʹÓà Laravel Ô´Âë¡£Laravel ÓµÓÐÍêÕûµÄÔ´ÂëºÍÎĵµ£¬ÎÒÃÇÉîÈëÑо¿ºÍʹÓÃËüÃÇ£¬¿ÉÒÔ×ÊÖúÎÒÃÇÏàʶºÍÕÆÎÕ Laravel ¿ò¼ÜµÄÊÂÇéÔÀíºÍʹÓÃÒªÁ졣ϣÍû±¾ÎÄÄܶԿí´ó¿ª·¢ÕßÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÏê½â Laravel µÄÔ´ÂëµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡