thinkphp 视图view
视图 View thinkphp
2023-09-27 14:23:50 时间
一. 继承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']); } }
相关文章
- mysql中,什么是视图,视图的作用是什么?
- 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录 contentEditable属性设置是否可编辑元素的内容 draggable属性设置元素是否可拖动。 请求一个action,将图片的二进制字节字符串在视图页面以图片形式输出
- C#反射实现 C# 反射 判断类的延伸类型 使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码 C# ADO.NET的SqlDataReader对象,判断是否包含指定字段 页面中添加锚点的几种方式 .net 简单实用Log4net(多个日志配置文件) C# 常用小点
- 自定义等待视图
- 数仓工具—Hive视图与物化视图(19)
- 《实用软件架构:从系统环境到软件部署 》——2.4 架构视图与架构视点
- MySQL创建视图(CREATE VIEW)
- 关于Android界面编程与视图(View)组件
- 小程序开发基础-swiper 滑块视图容器
- 视图控制器生命周期中各个重要的方法(Swift) (Important Methods during the Lifecycle of a View Controller)
- SAP RETAIL初阶之商品主数据WM视图
- SpringMVC 返回 html 视图页面,SpringMVC与Servlet,Servlet重定向与转发
- Android应用程序窗口(Activity)的视图对象(View)的创建过程分析
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- Android编程动态创建视图View的方法
- SwiftUI UI高级技巧之实现Table表格类组件基于多视图测量并限定宽度
- SwiftUI 常用组件之 可刷新滚动视图View支持scrollview list
- SwiftUI手势之控制视图旋转 获取实时度数 实现360度旋转效果 (教程含源码)
- SwiftUI 高手思维之 02 View视图使用最简单的基础类型这是一种极好的实践
- Android View体系(一)视图坐标系
- View Controller 视图管理总结
- 小程序框架之视图层 View
- 小程序框架之视图层 View~事件系统~WXS响应事件
- 视图控制器
- Android View体系(一)视图坐标系
- Python django写视图函数request的方法和属性没有自动补全代码提示(包括写其他代码的时候函数参数的变量没有代码提示)
- [Django]views中视图函数获取不到form表单提交的文件,request.FILES为空
- 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(四)Alert View视图 学习笔记