学习ThinkPHP3.2.2(三):读取指定的记录
来源:互联网 发布:淘宝所在地区怎么设置 编辑:程序博客网 时间:2024/06/11 16:41
根据3.1的入门教程CURD http://www.thinkphp.cn/info/101.html,想在3.2下运行成功,像我这样的初学者还真是有难度。C过程试了好长时间都不行,估计目录结构、文件命名、URL参数等等都有可能有问题,但是我不清楚。那试试R过程吧。以(二)的目录和文件为基础。
1、先在数据库中创建一个think_form表:
CREATE TABLE IF NOT EXISTS `think_form` (
`id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`content` varchar(255) NOT NULL,
`create_time` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
插入两条数据,便于我们测试:
INSERT INTO `think_form` (`id`, `title`, `content`, `create_time`) VALUES
(1, 'title1', 'content1', 0),
(2, 'title2', 'content2', 0);
2、建模板文件 D:\wamp\www\MyWeb\Application\Home\View\Read\read.html:
<html>
<head>
<title>read Data</title>
</head>
<body>
<table>
<tr>
<td>id:</td>
<td>{$data.id}</td>
</tr>
<tr>
<td>标题:</td>
<td>{$data.title}</td>
</tr>
<tr>
<td>内容:</td>
<td>{$data.content}</td>
</tr>
</table>
</body>
</html>
3、建控制器:D:\wamp\www\MyWeb\Application\Home\Controller\ReadController.class.php:
<?php
namespace Home\Controller;
use Think\Controller;
class ReadController extends Controller {
public function read($id=0){
$Form = M('Form');
// 读取数据
$data = $Form->find($id);
if($data) {
$this->data = $data;// 模板变量赋值
}else{
$this->error('数据错误');
}
$this->display();
}
}
4、浏览:http://localhost/MyWeb/index.php/Home/Read/read/id/2
http://localhost/MyWeb/index.php/Home/Read/read/id/1
- 学习ThinkPHP3.2.2(三):读取指定的记录
- ThinkPHP3.2.2学习记录
- 学习ThinkPHP3.2.2(四):增加记录
- 学习ThinkPHP3.2.2(五):编辑记录
- 学习ThinkPHP3.2.2(一):记录一下第一个例子的运行过程
- 学习ThinkPHP3.2.2:video15,删除记录
- ThinkPHP3.2.3学习记录(一)
- thinkphp3.2学习记录
- 学习ThinkPHP3.2.2:video10,设置模板读取控制器中某个操作的url
- 学习ThinkPHP3.2.2:video8,以数组方式显示插入的记录
- 学习ThinkPHP3.2.2:video9,用“C”函数读取配置文件内容
- lucene.net 读取指定页数的记录
- Spring学习系列 : 错误记录(三) MyBatis日期读取
- 基于ThinkPHP3.2.3后台登录界面学习记录(二)
- 学习ThinkPHP3.2.2:模板文件的加载
- thinkphp3.1.3源码分析(2)配置项的读取
- thinkphp3.2.2学习笔记
- 记录java的学习历程(三)
- 2200:Eddy's AC难题
- 史上最好的mybatis入门教程(官网)
- ini文件二之操作
- vs中常用的快捷键
- Express学习之指南<3>
- 学习ThinkPHP3.2.2(三):读取指定的记录
- 博客迁移
- androidstudio获取sha1
- c++ 什么情况下需要将基类的析构函数声明为虚函数
- 垂直居中
- 实现从一个应用程序内部跳转到另一个应用程序的Demo
- 千里码-git
- [备忘] redis 生产环境配置
- 软件开发,怎么才能做好呢?(一)