一. 继承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的更多相关文章

  1. ThinkPHP视图查询

    ThinkPHP视图查询 一.总结 1.这里的视图查询和多表查询很像,当然多表查询的话肯定要支持左右链接查询 2.view:视图的使用,关键字是view 3.sql视图功能支持:thinkphp支持视 ...

  2. 使用mvc时,在视图view中使用强类型视图,在web.config文件中添加命名空间namespace的引用不起作用,解决方法

    这是view中的model代码: @model t_user_info 这是web.config配置文件只的代码: <namespaces> <add namespace=" ...

  3. SQL Server 索引(index) 和 视图(view) 的简单介绍和操作

    --索引(index)和视图(view)-- --索引(index)----概述: 数据库中的索引类似于书籍的目录,他以指针形式包含了表中一列或几列组合的新顺序,实现表中数据库的逻辑排序.索引创建在数 ...

  4. UIViewController的生命周期(根视图view从无到有的过程)

    UIViewController的生命周期实质上是指根视图view从无到有的过程 1.首先新建一个工程:不从mainstoryBoard加载 (删除入口) 在AppDelegate.m --> ...

  5. 视图(View)与部分视图(Partial View)之间数据传递

    写ASP.NET MVC程序,我们经常需要把数据从视图(View)传递至部分视图(Partial View) 或者相反. 今天Insus.NET使用 ControllerBase.TempData 进 ...

  6. MVC中视图View向控制器传值的方法

    MVC中视图View向控制器传值的方法步骤如下: 1.index页面: 页面中只需要一个触发事件的按钮

  7. Oracle 学习笔记 11 -- 视图 (VIEW)

    本次必须学习一个全新的概念-- 视图 (VIEW).在前面的笔记中曾提到过,数据对象包含:表.视图.序列.索引和同义词.前面的笔记都是对表的想剖析,那么本次笔记就对视图的世界进行深入的剖析. 视图是通 ...

  8. Android编程动态创建视图View的方法

    在Android开 发中,在Activity中关联视图View是一般使用setContentView方法,该方法一种参数是使用XML资源直接创 建:setContentView (int layout ...

  9. 关于Android界面编程与视图(View)组件

    UI组件--------------->android.widget.* View组件------------->android.view.* 视图(View)组件 所有UI组件都是建立在 ...

随机推荐

  1. 在ubuntu12.4上安装minigui3.0.12

      在ubuntu12.4上安装minigui3.0.12 一下载源文件 移植所需的文件可以从minigui官网下载:http://www.minigui.org/en/download/ 主要文件有 ...

  2. requirejs define a module

    https://requirejs.org/docs/api.html#define Define a Module § 1.3 A module is different from a tradit ...

  3. React-Native 之 GD (一)目录结构与第三方框架使用与主题框架搭建

    1.APP效果图 2.工程环境配置 IOS: 将压缩包内的 Images.xcassets 文件夹直接替换掉我们iOS工程中的 Images.xcassets 文件夹. 这时候我们可以看到所有图片资源 ...

  4. 【C++进阶:STL常见性质】

    STL中的常用容器包括:顺序性容器(vector.deque.list).关联容器(map.set).容器适配器(queue.stac) 转载自:https://blog.csdn.net/u0134 ...

  5. 《图解 TCP-IP(第 5 版)》

    第一章 网络基础知识 计算机网络根据规模可以分为:广域网(WAN: Wide Area Network)和局域网(LAN: Local Area Network) 协议的标准化: 国际标准化组织(IS ...

  6. 用Vue来实现音乐播放器(八):自动轮播图啊

    slider.vue组件的模板部分 <template> <div class="slider" ref="slider"> <d ...

  7. 错误 error: The following untracked working tree files would be overwritten by merge:README.md

    问题类型 相信很多小伙伴在创建新的git仓库后,会选上添加README.md文件,开始我也没太在意,应该也没有什么问题. 但是当我通过git添加远程仓库,给这个仓库上传代码时,出现了如下问题:erro ...

  8. final关键字的案例

    package com.company.java.oop.cls; class ClassF { // static ClassF instance =new ClassF(); static { S ...

  9. Idea maven远程调试(pom配置tomcat)

    服务器端,maven内置tomcat启动命令:mvnDebug clean tomcat7:run -Dmaven.test.skip=true 服务器端:配置(vim或者文件模式打开mvnDebug ...

  10. jenkins 启动报错

    daemon: fatal: refusing to execute unsafe program: /usr/java/jdk1.8.0/bin/java (/usr/java/jdk1.8.0/b ...