一. 继承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. Web引用中文个性字体

    最近在前端开发时,因为设计的原因,要引用一些特殊字体(otf格式),但是后来发现这些字体文件非常大,平均每个要8mb左右,严重影响了网页效率.经过一番搜索,发现了前端字体压缩工具(只支持utf-8格式 ...

  2. O(1)得到螺旋矩阵的值

    LL ind(LL x, LL y, LL n){ LL qs = n / , q = min(n - y + , min(n - x + , min(x, y))) - ; && y ...

  3. uva live 7638 Number of Connected Components (并查集)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  4. [转]玩转Google开源C++单元测试框架Google Test系列(gtest)(总)

    文章转载自CoderZh的技术博客 地址:https://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html 前段时间学习和了解了下Goog ...

  5. p5437 【XR-2】约定

    分析 https://www.cnblogs.com/cjyyb/p/11111404.html 代码 #include<bits/stdc++.h> using namespace st ...

  6. 图论&线性基(?)(8.12)

    边没有负权,最短路最多只有n条边 很暴力的思想: 先跑一遍最短路,找出最短路上的边,枚举每条边,翻倍,放进原图再跑一遍.取最大值 好熟悉啊 分层建图,建k层 每层内部是原图 若原图中u到v有连边,则由 ...

  7. flex embed 使用

    Flex 软件中经常需要使用一些外部的资源,如图片.声音.SWF或字体,虽然你也可以在软件运行的时候引入和载入,但是也可能经常需要直接将这些资源编译(Compile)到软件中,也就是直接嵌入资源(Em ...

  8. curl发json

    linux 模拟post请求 curl -X POST \ -H "Content-Type: application/json" \ -H "token:GXJP1cl ...

  9. LeetCode——142 设计链表2

    题目 代码 class Solution { public: ListNode *detectCycle(ListNode *head) { ListNode *fast = head, *slow ...

  10. Where we love is home, home that our feet may leave, but not our hearts.

    parcel.n. 包裹 endurance.n.耐力 rot.v.腐烂 ornament.n.装饰 pinch.v.捏 nationality.n.国家 sunshine.n.阳光 stagger. ...