亚洲精品高清国产一久久_日韩v亚洲v欧美v精品综合 日韩网红少妇无码视频香港_国产在线观看免费观看_粉

0712-2888027 189-8648-0214
微信公眾號(hào)

孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號(hào)

當(dāng)前位置:主頁(yè) > 技術(shù)支持 > PHP > Laravel Controller控制器傳值到View視圖的幾種方法

Laravel Controller控制器傳值到View視圖的幾種方法

時(shí)間:2019-01-08來源:風(fēng)信官網(wǎng) 點(diǎn)擊: 1418次

總體內(nèi)容分為傳值類型和方法,大概總體感覺如下。

傳值類型:一個(gè)值,多個(gè)值,數(shù)組。
方法: with,view,compact
默認(rèn)視圖 test文件下index.blade.php

單個(gè)值的傳遞

with

public function index() {
  $test = "測(cè)試";
  return view('test.index')->with('test',$test);
}

view

public function index() {
    return view('test.index', ['test' => '測(cè)試']);
}

compact

public function index() {
  $test = "測(cè)試";
  return view('test.index',compact('test'));
}

多個(gè)值的傳遞

with

public function index() {
  return view('test.index')->with(["test1" => "測(cè)試1", "test2" => "測(cè)試2", "test3" => "測(cè)試3"]);
}

view

public function index() {
  return view('test.index', ['test1' => '測(cè)試1','test2' => '測(cè)試2','test3' => '測(cè)試3']);
}

compact

public function index() {
  $test_1 = "測(cè)試1";
  $test_2 = "測(cè)試2";
  $test_2 = "測(cè)試3";
  return view('test.index',compact('test_1','test_2' ,'test_3' ));
}

數(shù)組的傳遞

with

public function index() {
  $data = array( 'test1' => '測(cè)試1', 'test2' => '測(cè)試2', 'test3' => '測(cè)試3' );
  return view('test.index')->with($data);
}

view

public function index() {
  $data["test1"] = "測(cè)試1";
  $data["test2"] = "測(cè)試2";
  $data["test3"] = "測(cè)試3";
  return view('test.index',$data);
}

compact

//推薦此種方法
public function index() {
  $test_array = ["測(cè)試1","測(cè)試2", "測(cè)試2"];
  return view('test.index',compact('test_array'));
}
熱門關(guān)鍵詞: Laravel Controller 控制器 傳值 View視圖
欄目列表
推薦內(nèi)容
熱點(diǎn)內(nèi)容
展開
无为县| 青海省| 同德县| 西乌| 镇宁| 昌宁县| 万盛区| 永泰县| 米泉市| 日照市| 塘沽区| 龙州县| 丹巴县| 牙克石市| 谢通门县| 青阳县| 蓝山县| 江孜县| 翼城县| 巴里| 玉山县| 江门市| 和龙市| 乳山市| 开原市| 永靖县| 囊谦县| 贡嘎县| 云阳县| 东阳市| 奎屯市| 博野县| 涪陵区| 陆良县| 丰台区| 达拉特旗| 武川县| 五华县| 康马县| 噶尔县| 河源市|