laravel ÕÒ²»µ½Ò³Ãæ
laravel ÊÇÒ»ÖÖÊ¢ÐÐµÄ php web ¿ª·¢¿ò¼Ü¡£ËüÌṩÁËһЩÓÐÓõĹ¦Ð§£¬Èç·ÓÉ¡¢¿ØÖÆÆ÷¡¢ÊÓͼµÈ£¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨¸ßЧµÄ web Ó¦ÓóÌÐò¡£µ«ÓÐʱ¼ä£¬µ±ÄãÔÚ¿ª·¢Ó¦ÓóÌÐòʱ£¬Äã¿ÉÄÜ»áÓöµ½¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£Õâ¸öÎÊÌâ¿ÉÄÜ»áÈÃÄãºÜÀ§ÈÅ£¬µ«²»±Øµ£ÐÄ£¬±¾ÎĽ«×ÊÖúÄã½â¾öÕâ¸öÎÊÌâ¡£
Ϊʲô»á·ºÆð¡°ÕÒ²»µ½Ò³Ã桱£¿
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÖªµÀΪʲô»á·ºÆð¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£Í¨³££¬Õâ¸ö¹ýʧÊÇÓÉÒÔÏÂÔµ¹ÊÔÓÉÒýÆðµÄ£º
¹ýʧµÄ·ÓÉ»ò URL¡£
ûÓÐÓë·ÓÉÆ¥ÅäµÄ¿ØÖÆÆ÷ÒªÁì¡£
ûÓÐÓë¿ØÖÆÆ÷ÒªÁìÆ¥ÅäµÄÊÓͼÎļþ¡£
ÊÓͼÎļþµÄ·¾¶¹ýʧ¡£
ÏÂÃ棬ÎÒÃǽ«»®·ÖÌÖÂÛÕâЩÎÊÌâÒÔ¼°ÔõÑù½â¾öËüÃÇ¡£
¹ýʧµÄ·ÓÉ»ò URL
ÔÚ Laravel ÖУ¬Â·ÓÉÊǽ« URL Ó³Éäµ½¿ØÖÆÆ÷ÒªÁìµÄÒ»ÖÖ·½·¨¡£ÈôÊÇÄãµÄ·ÓÉ»ò URL ²»×¼È·£¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£ÀýÈ磬ÈôÊÇÄãµÄ·ÓÉÊÇÕâÑùµÄ£º
Route::get('/example', 'ExampleController@index');
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÄÇô£¬ÄãÓ¦¸Ã»á¼û URL http://yourdomain.com/example ¡£ÈôÊÇÄã»á¼ûÁË http://yourdomain.com/examples £¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
½â¾ö²½·¥£º
È·±£Äã»á¼ûµÄ URL ÓëÄãµÄ·ÓÉÆ¥Åä¡£Äã¿ÉÒÔÉó²éÄãµÄ·ÓÉÎļþ£¬»òÕßʹÓà php artisan route:list ÏÂÁîÉó²éËùÓнç˵µÄ·ÓÉ¡£ÈôÊÇÄãÒѾȷ¶¨ÄãµÄ·ÓÉºÍ URL ÊÇ׼ȷµÄ£¬ÄÇôÄãÐèÒª¼ì²éÒÔÏÂÎÊÌâ¡£
ûÓÐÓë·ÓÉÆ¥ÅäµÄ¿ØÖÆÆ÷ÒªÁì
ÔÚ Laravel ÖУ¬¿ØÖÆÆ÷ÊÇ´¦Àí HTTP ÇëÇóµÄÒ»ÖÖ·½·¨¡£ÈôÊÇÄãµÄ·ÓÉ׼ȷ£¬µ«¿ØÖÆÆ÷ÒªÁì²»±£´æ£¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
ÀýÈ磬ÈôÊÇÄãµÄ·ÓÉÊÇÕâÑùµÄ£º
Route::get('/example', 'ExampleController@index');
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÄÇô£¬ÄãµÄ ExampleController ÀàÓ¦¸ÃÓÐÒ»¸öÃûΪ index µÄÒªÁ죺
class ExampleController extends Controller { public function index() { return view('example'); } }
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÈôÊÇÄãµÄ ExampleController ÀàûÓÐ index ÒªÁ죬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
½â¾ö²½·¥£º
È·±£ÄãµÄ¿ØÖÆÆ÷ÒªÁì±£´æ¡£Äã¿ÉÒÔ¼ì²éÄãµÄ¿ØÖÆÆ÷Îļþ£¬»òÕßʹÓà php artisan route:list ÏÂÁîÉó²éËùÓнç˵µÄ·ÓɺͿØÖÆÆ÷ÒªÁì¡£ÈôÊÇÄãÒѾȷ¶¨ÄãµÄ¿ØÖÆÆ÷ÒªÁì±£´æ£¬ÄÇôÄãÐèÒª¼ì²éÒÔÏÂÎÊÌâ¡£
ûÓÐÓë¿ØÖÆÆ÷ÒªÁìÆ¥ÅäµÄÊÓͼÎļþ
ÔÚ Laravel ÖУ¬ÊÓͼÊÇÏÔʾ HTML Ò³ÃæµÄÒ»ÖÖ·½·¨¡£ÈôÊÇÄãµÄ·ÓɺͿØÖÆÆ÷ÒªÁì׼ȷ£¬¿ÉÊÇÊÓͼÎļþ²»±£´æ£¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
ÀýÈ磬ÈôÊÇÄãµÄ¿ØÖÆÆ÷ÒªÁì·µ»ØÊÓͼ example£º
class ExampleController extends Controller { public function index() { return view('example'); } }
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÄÇô£¬ÄãµÄÊÓͼÎļþÓ¦¸ÃλÓÚ resources/views/example.blade.php ¡£
ÈôÊÇÄãµÄÊÓͼÎļþ²»±£´æ£¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
½â¾ö²½·¥£º
È·±£ÄãµÄÊÓͼÎļþ±£´æ¡£Äã¿ÉÒÔ¼ì²éÄãµÄÊÓͼÎļþ·¾¶£¬»òÕßʵÑéÔÚ¿ØÖÆÆ÷ÒªÁìÖзµ»ØÒ»¸ö¼òÆÓµÄ×Ö·û´®£¬ÒÔÈ·±£¿ØÖÆÆ÷ºÍÊÓͼÎļþ¶¼Õý³£ÊÂÇé¡£ÈôÊÇÄãÒѾȷ¶¨ÄãµÄÊÓͼÎļþ±£´æ£¬ÄÇôÄãÐèÒª¼ì²éÒÔÏÂÎÊÌâ¡£
ÊÓͼÎļþµÄ·¾¶¹ýʧ
ÔÚ Laravel ÖУ¬ÊÓͼÎļþµÄ·¾¶ºÜÊÇÖ÷Òª¡£ÈôÊÇÄãÔÚÊÓͼÎļþµÄ·¾¶Öз¸Á˹ýʧ£¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
ÀýÈ磬ÈôÊÇÄãµÄ¿ØÖÆÆ÷ÒªÁì·µ»ØÊÓͼ example£º
class ExampleController extends Controller { public function index() { return view('example'); } }
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÄÇô£¬ÄãµÄÊÓͼÎļþÓ¦¸ÃλÓÚ resources/views/example.blade.php ¡£
ÈôÊÇÄ㽫ÊÓͼÎļþ·ÅÔÚ¹ýʧµÄ·¾¶Ï£¬Äã¾Í»á»ñµÃ¡°ÕÒ²»µ½Ò³Ã桱µÄ¹ýʧ¡£
½â¾ö²½·¥£º
È·±£ÄãµÄÊÓͼÎļþ·¾¶×¼È·¡£Äã¿ÉÒÔ¼ì²éÄãµÄ¿ØÖÆÆ÷ÒªÁìÖеÄÊÓͼÎļþÃûÊÇ·ñ׼ȷ£¬ÒÔ¼°ÄãµÄÊÓͼÎļþÊÇ·ñλÓÚ׼ȷµÄĿ¼Ï¡£ÈôÊÇÄãÒѾȷ¶¨ÄãµÄÊÓͼÎļþ·¾¶×¼È·£¬ÄÇôÄãÐèÒª¼ì²éÒÔÏÂÎÊÌâ¡£
½áÂÛ
¡°ÕÒ²»µ½Ò³Ã桱ÊÇÒ»¸öºÜ³£¼ûµÄ¹ýʧ£¬ÔÚ Laravel ¿ª·¢Öо³£·ºÆð¡£ÈôÊÇÄãÓöµ½Õâ¸ö¹ýʧ£¬Ê×Ïȼì²éÄãµÄ·ÓÉ¡¢¿ØÖÆÆ÷ÒªÁìºÍÊÓͼÎļþµÄ·¾¶ÊÇ·ñ׼ȷ¡£ÈôÊÇÄãÈÔÈ»ÎÞ·¨½â¾öÎÊÌ⣬¿ÉÒÔʵÑéÔÚ¿ØÖÆÆ÷Öзµ»ØÒ»¸ö¼òÆÓµÄ×Ö·û´®£¬ÒÔÈ·±£¿ØÖÆÆ÷ºÍÊÓͼÎļþ¶¼Õý³£ÊÂÇ顣ϣÍû±¾ÎĶԽâ¾ö¡°ÕÒ²»µ½Ò³Ã桱µÄÎÊÌâÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇlaravel ÕÒ²»µ½Ò³ÃæµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡