thinkphp 视图view
一. 继承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']);
} }
thinkphp 视图view的更多相关文章
- ThinkPHP视图查询
ThinkPHP视图查询 一.总结 1.这里的视图查询和多表查询很像,当然多表查询的话肯定要支持左右链接查询 2.view:视图的使用,关键字是view 3.sql视图功能支持:thinkphp支持视 ...
- 使用mvc时,在视图view中使用强类型视图,在web.config文件中添加命名空间namespace的引用不起作用,解决方法
这是view中的model代码: @model t_user_info 这是web.config配置文件只的代码: <namespaces> <add namespace=" ...
- SQL Server 索引(index) 和 视图(view) 的简单介绍和操作
--索引(index)和视图(view)-- --索引(index)----概述: 数据库中的索引类似于书籍的目录,他以指针形式包含了表中一列或几列组合的新顺序,实现表中数据库的逻辑排序.索引创建在数 ...
- UIViewController的生命周期(根视图view从无到有的过程)
UIViewController的生命周期实质上是指根视图view从无到有的过程 1.首先新建一个工程:不从mainstoryBoard加载 (删除入口) 在AppDelegate.m --> ...
- 视图(View)与部分视图(Partial View)之间数据传递
写ASP.NET MVC程序,我们经常需要把数据从视图(View)传递至部分视图(Partial View) 或者相反. 今天Insus.NET使用 ControllerBase.TempData 进 ...
- MVC中视图View向控制器传值的方法
MVC中视图View向控制器传值的方法步骤如下: 1.index页面: 页面中只需要一个触发事件的按钮
- Oracle 学习笔记 11 -- 视图 (VIEW)
本次必须学习一个全新的概念-- 视图 (VIEW).在前面的笔记中曾提到过,数据对象包含:表.视图.序列.索引和同义词.前面的笔记都是对表的想剖析,那么本次笔记就对视图的世界进行深入的剖析. 视图是通 ...
- Android编程动态创建视图View的方法
在Android开 发中,在Activity中关联视图View是一般使用setContentView方法,该方法一种参数是使用XML资源直接创 建:setContentView (int layout ...
- 关于Android界面编程与视图(View)组件
UI组件--------------->android.widget.* View组件------------->android.view.* 视图(View)组件 所有UI组件都是建立在 ...
随机推荐
- Spring Boot 异步方法的调用
Spring Boot 异步方法的调用 参考资料: 1.Spring Boot中使用@Async实现异步调用 使用方法 两个步骤: 1.开启配置 @EnableAsync,这一步特别容易忘记,导致测试 ...
- Ecipse代码调试
1.设置断点 2.启动调试 在代码空白处中右击,选择Debug as —>1 Java Application 快捷键 表示当前实现继续运行直到下一个断点,快捷键为F8. 表示打断整个进程 表示 ...
- [django]上下文管理器
上下文管理器django提取context中的数据去供模板调用 需求: 所有的页面都需要一个特定的变量 本质: python函数 , 接收一个HttpRequest对象的参数 , 且返回的必须是一个字 ...
- Java 实现 对象和转字符串之间的互转 (json格式)
添加依赖: <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> ...
- Hyperledger交易流程
Hyperledger Fabric Network中的角色 在Hyperledger中,由三种类型的角色: Client:应用客户端,用于将终端用户的交易请求发送到区块链网络: Peers:负责维护 ...
- JavaScript method overload
https://stackoverflow.com/questions/2187666/help-with-js-and-functions-parameters JavaScript doesn' ...
- mysql的my.cnf参数详解
转载[Mysql] MySQL配置文件my.cnf的理解 一.缘由 最近要接手数据库的维护工作,公司首选MySQL.对于MySQL的理解,我认为很多性能优化工作.主从主主复制都是在调整参数,来适应不同 ...
- springBoot项目常用maven依赖以及依赖说明
springBoot项目常用maven依赖以及依赖说明 1:maven-compiler-plugin <build> <plugins> <!-- 指定maven编译的 ...
- 002-Spring4 快速入门-项目搭建、基于注解的开发bean,Bean创建和装配、基于注解的开发bean,Bean初始化销毁、Bean装配,注解、Bean依赖注入
一.项目搭建 1.项目创建 eclipse→project explorer→new→Project→Maven Project 默认配置即可创建项目 2.spring配置 <dependenc ...
- 阿里云SLB产品HTTP、HTTPS、UDP协议使用
1.http协议测试 第一步:添加http监听服务,前端端口为8080,后端端口为80,健康检查中检查端口为后端端口80: 第二步:在绑定的服务器上安装服务,步骤如下 centos系统中启动http协 ...