国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

[Laravel] Laravel的根本使用

php中文網(wǎng)
發(fā)布: 2016-06-13 12:29:08
原創(chuàng)
1053人瀏覽過

[Laravel] Laravel的基本使用

[laravel] laravel的基本http路由

?

使用Laravel的基本路由,實現(xiàn)get請求響應(yīng),找到文件app/Http/routes.php

調(diào)用Route的靜態(tài)方法get(),實現(xiàn)get響應(yīng),參數(shù):string類型的路徑,匿名函數(shù)function(){}

匿名函數(shù)內(nèi)部,返回string數(shù)據(jù)

?

實現(xiàn)post,put,delete的請求,同上

?

實現(xiàn)get傳遞參數(shù)的路由,調(diào)用Route的靜態(tài)方法get(),參數(shù):路徑,匿名函數(shù)

路徑,大括號包裹參數(shù)名,不含$,例如:’/user/{id}’

匿名函數(shù),接收參數(shù),例如:function($id){}

?

[Laravel] Laraval的基本控制器

?

在app/Http/Controllers目錄下,新建一個Index/IndexController.php

定義命名空間,namespace App\Http\Controllers\Index

引入Controller基本控制器,use App\Http\Controllers\Controller

定義IndexController繼承Controller

實現(xiàn)方法index,返回數(shù)據(jù)

定義路由指定控制器的行為,例如:Route::get("/index","Index\[email?protected]");,

注意命名空間部分,新建的控制器是在根命名空間下面,指定的時候添加自己新加的命名空間

?

[Laravel] Laravel的基本視圖

在目錄resources/views/下面,創(chuàng)建index/index.php

在控制器中使用函數(shù)view()來調(diào)用模板,參數(shù):文件路徑(.分隔目錄),數(shù)據(jù)

?

路由:routes.php

?

<?<span style="color: #000000;">php</span><span style="color: #008000;">/*</span><span style="color: #008000;">|--------------------------------------------------------------------------| Routes File|--------------------------------------------------------------------------|| Here is where you will register all of the routes in an application.| It's a breeze. Simply tell Laravel the URIs it should respond to| and give it the controller to call when that URI is requested.|</span><span style="color: #008000;">*/</span><span style="color: #008000;">/*</span><span style="color: #008000;">測試get post</span><span style="color: #008000;">*/</span><span style="color: #000000;"> Route::get(</span>'/'<span style="color: #000000;">, function () {    $url</span>=url("index"<span style="color: #000000;">);    </span><span style="color: #0000ff;">return</span> "Hello World"<span style="color: #000000;">.$url;    </span><span style="color: #008000;">//</span><span style="color: #008000;">return view('welcome');</span><span style="color: #000000;">});Route::post(</span>"/post"<span style="color: #000000;">,function(){    </span><span style="color: #0000ff;">return</span> "測試post"<span style="color: #000000;">;});</span><span style="color: #008000;">/*</span><span style="color: #008000;">傳遞參數(shù)</span><span style="color: #008000;">*/</span><span style="color: #000000;">Route::get(</span>"/user/{id}"<span style="color: #000000;">,function($id){    </span><span style="color: #0000ff;">return</span> "用戶"<span style="color: #000000;">.$id;});</span><span style="color: #008000;">/*</span><span style="color: #008000;">使用控制器</span><span style="color: #008000;">*/</span><span style="color: #000000;">Route::get(</span>"/index","Index\[email&#160;protected]"<span style="color: #000000;">);</span><span style="color: #008000;">/*</span><span style="color: #008000;">|--------------------------------------------------------------------------| Application Routes|--------------------------------------------------------------------------|| This route group applies the "web" middleware group to every route| it contains. The "web" middleware group is defined in your HTTP| kernel and includes session state, CSRF protection, and more.|</span><span style="color: #008000;">*/</span><span style="color: #000000;">Route::group([</span>'middleware' => ['web'<span style="color: #000000;">]], function () {    </span><span style="color: #008000;">//</span>});
登錄后復(fù)制

?

控制器:IndexController.php

?

<?<span style="color: #000000;">phpnamespace App\Http\Controllers\Index;use App\Http\Controllers\Controller;</span><span style="color: #0000ff;">class</span> IndexController <span style="color: #0000ff;">extends</span><span style="color: #000000;"> Controller{    </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> function index(){        $data</span>=<span style="color: #000000;">array();        $data[</span>'title']="Index控制器"<span style="color: #000000;">;        </span><span style="color: #0000ff;">return</span> view("index.index"<span style="color: #000000;">,$data);    }}</span>
登錄后復(fù)制

?

模板:index.php

    <span style="color: #0000ff;"><</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span>        <span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="container"</span><span style="color: #0000ff;">></span>            <span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="content"</span><span style="color: #0000ff;">></span>                <span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="title"</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"><?</span><span style="color: #ff00ff;">php echo $title;</span><span style="color: #0000ff;">?></span><span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>            <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>        <span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>    <span style="color: #0000ff;"></</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span>
登錄后復(fù)制

?

最佳 Windows 性能的頂級免費優(yōu)化軟件
最佳 Windows 性能的頂級免費優(yōu)化軟件

每個人都需要一臺速度更快、更穩(wěn)定的 PC。隨著時間的推移,垃圾文件、舊注冊表數(shù)據(jù)和不必要的后臺進程會占用資源并降低性能。幸運的是,許多工具可以讓 Windows 保持平穩(wěn)運行。

下載
相關(guān)標簽:
來源:php中文網(wǎng)
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權(quán)歸原作者所有,本站不承擔相應(yīng)法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn
最新問題
開源免費商場系統(tǒng)廣告
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關(guān)于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號