ThinkPHP学习(三)
我们已经将数据保存到了后台数据库,那接下来我们肯定要将数据显示出来看看了。
先建立一个要显示数据的模板formlist.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThinkPHP</title>
</head>
<style type="text/css">
table {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
text-align: center;
}
table th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
} </style>
<body>
<div class="main">
<h2>你好</h2> <table align=center>
<tr>
<th>主题</th><th>内容</th>
</tr>
<volist name="list" id="vo" empty="暂时没有数据">
<tr>
<td>{$vo.title}</td><td>{$vo.content}</td>
</tr>
</volist> </table> </div>
</body>
</html>
然后在后台保存成功后接着调用显示:
<?php
class IndexAction extends Action{
public function index(){
$hello='Hello,ThinkPHP !';
$this->assign('hello',$hello);
$this->display();
}
public function add(){
$form = M('Form');
$form->create();
$form->add();
$this->redirect('Index/formlist');
}
public function formlist(){
$form = M('Form');
$vo=$form->select();
$this->assign('list',$vo);
$this->display();
}
}
对,就是简单地修改一下add()方法,保存成功后重定向显示模板,然后在formlist()中显示出所有数据来。
注意方法名字和模板名字要匹配噢。
再试试保存,保存后会直接打开显示所有保存结果的页面。当然了,实际中不能这么简单地显示所有数据。
ThinkPHP学习(三)的更多相关文章
- ThinkPHP学习总结
ThinkPHP学习总结 网站开发使用的thinkPHP5.0在此总结备查 MVC关系功能图 一.Thinkphp开发规范 l 类 类库.函数文件统一以.php为后缀: 类的文件名均以命名空间定义,并 ...
- ThinkPhp学习12
原文:ThinkPhp学习12 二.输出模板内容 (重点) a.display 1.display中没有参数 $this->display(); 2.可以带参数 $this ...
- ThinkPhp学习08
原文:ThinkPhp学习08 一.普通查询方式 a.字符串 $arr=$m->where("sex=0 and username='gege'")->find(); ...
- ThinkPhp学习09
原文:ThinkPhp学习09 三.区间查询 $data['id']=array(array('gt',4),array('lt',10));//默认关系是 and 的关系 //SELECT * FR ...
- ThinkPhp学习05
原文:ThinkPhp学习05 一.ThinkPHP 3 的CURD介绍 (了解)二.ThinkPHP 3 读取数据 (重点) 对数据的读取 Read $m=new Model('User') ...
- Thinkphp学习04
原文:Thinkphp学习04 一.ThinkPHP 3 的输出 (重点) a.通过 echo 等PHP原生的输出方式在页面中输出 b.通过display方法输出 想分配变量可以使用as ...
- ThinkPhp学习02
原文:ThinkPhp学习02 一.什么是MVC M -Model 编写model类 对数据进行操作 V -View 编写html文件,页面呈现 C -Controll ...
- ThinkPhp学习01
原文:ThinkPhp学习01 一.ThinkPHP的介绍 MVC M - Model 模型 工作:负责数据的操作 V - View 视图(模板 ...
- thinkphp学习笔记10—看不懂的路由规则
原文:thinkphp学习笔记10-看不懂的路由规则 路由这部分貌似在实际工作中没有怎么设计过,只是在用默认的设置,在手册里面看到部分,艰涩难懂. 1.路由定义 要使用路由功能需要支持PATH_INF ...
随机推荐
- Linux上安装Hadoop集群(CentOS7+hadoop-2.8.0)
1下载hadoop 2安装3个虚拟机并实现ssh免密码登录 2.1安装3个机器 2.2检查机器名称 2.3修改/etc/hosts文件 2.4 给3个机器生成秘钥文件 2.5 在hserver1上创建 ...
- MFC中如何给静态文本框添加消息响应
需要两个步骤: 第一个: 是改变它的ID(默认情况下所有的静态文本框的ID都为IDC_STATIC,你需要改变他的ID为其他的值). 第二个: 是在它的属性对话框中选中Notify选项,VS是将该属性 ...
- Android基于RecyclerView实现高亮搜索列表
这篇应该是RecycleView的第四篇了,RecycleView真是新生代的宠儿能做这么多的事情. 转载请注明作者AndroidMsky及原文链接 http://blog.csdn.net/Andr ...
- Android -- DecorView
DecorView 开发中,通常都是在onCreate()中调用setContentView(R.layout.custom_layout)来实现想要的页面布局.页面都是依附在窗口之上的,而Decor ...
- 在浏览器中直接调用webservice的正确写法
此文章针对webwork+spring+hibernate的工程,对于其他框架应该一样适用,首先在wsdd文件中找到所需webservice的名称,例如以下写法: <service name=& ...
- Centos下配置单元测试工具gtest
gtest是google提供的一个非常强大的单元测试工具,下载地址:https://code.google.com/p/googletest 我下载的是gtest-1.6.0.拷贝到Centos系统上 ...
- (转)unity3D 如何提取游戏资源 (反编译)+代码反编译
原帖:http://bbs.9ria.com/thread-401140-1-1.html 首先感谢 雨松MOMO 的一篇帖子 教我们怎么提取 .ipa 中的游戏资源.教我们初步的破解unity3d资 ...
- The future of scripting in Unity
Recently we talked about Unity and WebGL . In that post we briefly spoke about how scripting works i ...
- HTTP协议中源端口和目标端口的问题
[提问] How is source port for HTTP determined? Is there ever collision in NAT? I know that when a HT ...
- Mongo如何在多个字段中查询某个关键字?
If a text index has multiple fields in Mongo, how can I do a search in only one field since the weig ...