一. 继承Controller类
<?php namespace app\index\controller; use http\Params;
use think\Config;
use think\Controller;
use think\Request; import('filter', APP_PATH . 'common', ".php"); class Index extends Controller
{
/**
* @param Request $request
* @return string|void
* @url http://localhost/news/5.html?name=jiang
*/
public function index(Request $request)
{
#fetch() 默认模板目录为 /application/index/view/index/index.html
# 传递第一个参是修改模板文件目录的
#(upload) /application/index/view/index/upload.html 参数无斜杠
#(public/upload) /application/index/view/public/upload.html 参数有斜杠
#(./index.html) thinkphp入口public目录的index.html
#(./html/index.html) thinkphp入口public目录的 html/index.html
# fetch() 的第二个参数传递数据, html中用${}接收 ,
#第三个参数如果定义了大写的键,则会将html中所有的和大写键 替换为相应的值 #assign()方法也可以传值,相当于fetch()第二个参数的作用
#$this->assign("assign",'assgin传递');
# return $this->fetch('index',['email'=>'432433434@gmail.com','user'=>'jiang',],['STATI'=>"替换内容"]); #display() 第一个参数返回内容,第二个参数返回变量
return $this->display('<h2>我的名字将{$name}.</h2>',['name'=>'jiang fei long']);
} }
二. view助手函数, 这种方法不推荐使用
<?php namespace app\index\controller; use http\Params;
use think\Config;
use think\Request; import('filter', APP_PATH . 'common', ".php"); class Index
{
/**
* @param Request $request
* @return string|void
* @url http://localhost/news/5.html?name=jiang
*/
public function index(Request $request)
{
# view() 默认模板目录为 /application/index/view/index/index.html
# 传递第一个参是修改模板文件目录的
#(upload) /application/index/view/index/upload.html 参数无斜杠
#(public/upload) /application/index/view/public/upload.html 参数有斜杠
#(./index.html) thinkphp入口public目录的index.html
#(./html/index.html) thinkphp入口public目录的 html/index.html
#(view 的第二个参数传递数据, html中用${}接收 ,
#第三个参数如果定义了大写的键,则会将html中所有的和大写键 替换为相应的值
return view('index',['email'=>'432433434@gmail.com','user'=>'jiang',],['STATI'=>"替换内容"]);
} }
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
this is view index.html
${$email}
${$user}
STATI
STATI
</body>
</html>
三. 继承Cotroller类
<?php namespace app\index\controller; use http\Params;
use think\Config;
use think\Controller;
use think\Request; import('filter', APP_PATH . 'common', ".php"); class Index extends Controller
{
/**
* @param Request $request
* @return string|void
* @url http://localhost/news/5.html?name=jiang
*/
public function index(Request $request)
{
#fetch() 默认模板目录为 /application/index/view/index/index.html
# 传递第一个参是修改模板文件目录的
#(upload) /application/index/view/index/upload.html 参数无斜杠
#(public/upload) /application/index/view/public/upload.html 参数有斜杠
#(./index.html) thinkphp入口public目录的index.html
#(./html/index.html) thinkphp入口public目录的 html/index.html
# fetch() 的第二个参数传递数据, html中用${}接收 ,
#第三个参数如果定义了大写的键,则会将html中所有的和大写键 替换为相应的值 #assign()方法也可以传值,相当于fetch()第二个参数的作用
#$this->assign("assign",'assgin传递');
# return $this->fetch('index',['email'=>'432433434@gmail.com','user'=>'jiang',],['STATI'=>"替换内容"]); #display() 第一个参数返回内容,第二个参数返回变量
return $this->display('<h2>我的名字将{$name}.</h2>',['name'=>'jiang fei long']);
} }