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组件都是建立在 ...
随机推荐
- vue中移动端自适应方案
安装 lib-flexible 1.npm i lib-flexible 2.在项目入口文件 main.js 里 引入 lib-flexible import ‘lib-flexible’ 3.添加m ...
- WAMPSERVER php
The Apache service named reported the following error:>>> (OS 10013)An attempt was made to ...
- [git] 如何处理push失败的commit
在使用git及github时,遇到一个问题:commit了一个超过100M的大文件,然后在push时失败,然后就再也无法push了,本地大文件删除了,再commit,再push也还是提示有大文件提交. ...
- GTID复制模式切换与传统主从复制间切换
GTID复制模式切换到传统主从复制主从复制环境:主库:10.18.10.11从库:10.18.10.12MySQL5.7.22 切换之前查看下主从gitd_mode参数值主服务器:gtid_mode值 ...
- JS text节点无innerHTML
在线预览 text节点无innerHTML这个属性!!! 如果直接修改text节点的属性(data,nodeValue,textContent),或者使用js原生的修改text节点的内容的方法都会将H ...
- centos输入正确的账号和密码登陆不进去
vm下启动centos,输入正确的账号和密码,依然登陆不进去,一直处于这个界面: 暂时的解决方法是:先等待一段时间.重启,然后再输入密码,然后,ctrl+c 不停地ctrl+c,然后就登陆进去了.什么 ...
- 008-Spring Boot @EnableAutoConfiguration深入分析、内部如何使用EnableAutoConfiguration
一.EnableAutoConfiguration 1.EnableAutoConfiguration原理 springboot程序入口使用注解@SpringBootApplication,Sprin ...
- iView 实战系列教程(21课时)_2.iView 实战教程之导航、路由、鉴权篇
在c盘创建一个iview-router的项目 . 然后使用默认的配置 跳过 添加vue-router的插件 编译我们的文件. 编译好之后,我们启动App 默认的页面就打开了. 默认两个路由一个是abo ...
- @SuppressWarnings https://www.cnblogs.com/fsjohnhuang/p/4040785.html
一.前言 编码时我们总会发现如下变量未被使用的警告提示: 上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了.这时我们可以在方法前添加 @SuppressWar ...
- Iview 启动报错 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
解决 fs.write(fd, buf, 0, buf.length, 0, function(err, written, buffer) {}); 替换为 fs.write(fd, buf, 0, ...