thinkphp 視圖(一)

視圖 Viewphp

<?php
namespace app\index\controller;
class Index{
    public function index(){
        return view();
    }
}
?>

默認調用當前模塊下view 目錄下 同名控制器的同名.html文件模板 html

return view('upload');

默認會找app/index/view/index/upload.html;app

return view('public/upload');

默認會找app/index/view/public/upload.htmlfetch

return view('./index.html');

默認會找入口文件同級的index.html文件this

return view('index',[
    'email'=>'1234@qq.com'
]);

傳入第二個參數spa

<p>{$email}</p>

頁面直接顯示對應內容code

return view('index',[
    'email'=>'1234@qq.com',
    'user'=>'xiaoming'
]);

能夠傳遞多個變量htm

第三個參數blog

return view('index',[
    'email'=>'1234@qq.com''user'=>'xiaoming'
],[
    'STATIC'=>'當前是static替換的內容'
]);

view頁面直接寫繼承

<p>STATIC</p>

能夠替換內容,不用花括號(不推薦使用)

====第二種方法,類型繼承自控制器類

<?php
namespace app\index\controller;

use think\Controller;
class Index extends Controller{
     public function index(){
          return $this.->fetch();
     }
}
?>

傳遞第一個參數

return $this->fetch('index');

fetch的第1、第2、三個參數和view()的用法同樣

繼承控制器方式能夠直接傳遞變量

$this->assign('assign','assign傳遞的值');

頁面獲取

<p>{$assign}</p>

直接返回文本內容

return $this->display('這是一個字符串');
return $this->display('這是{$email}一個字符串',[
          'email'=>'3124@qq.com'
]);
相關文章
相關標籤/搜索