[PHP,Laravel5.4]入門學習筆記01-路由入門

在laravel目錄下routes>web.php 所有的導向設定都在這邊

而你的網頁檔案則放在resources\views

現在來看一下路由基本用法(web.php)

先知道我的主機位址在 http://127.0.0.1/laravel/public/

首頁就可以這樣設定

Route::get('/',function(){
    return view('index');
     //抓取放在resources\views底下的index.php 或是index.blade.php
});

Route::get('test1/{id}', function ($id) {
    return 'User '.$id;
   //試試看:你的主機位址/test1/666
});

Route::get('test2/{id?}', function ($id) {
    return 'User '.$id;
   //這邊在id後面多了?表示這是一個可以選填的變數
});

通過上面的示範大概也知道除了丟檔案進去目錄外,還需要在web.php上設定路由才能顯示出網頁畫面。使用get的方式也與純php使用?id=xxx的方式不一樣

更多介紹請待下一篇...

留言

這個網誌中的熱門文章

[Arduino]電子秤平 重量感測條+HX711AD模組

cpe練習筆記 UVa401 Palindromes

cpe練習筆記 UVa10019 Funny Encryption Method