配置
1.配置
<?php
return array(
//'配置项'=>'配置值'
'DEFAULT_MODULE' => 'Admin', // 默认模块
'DEFAULT_CONTROLLER' => 'Index', // 默认控制器名称
'DEFAULT_ACTION' => 'index', // 默认操作名称
'DB_TYPE' => 'mysqli', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'thinkphp0421', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => 'root', // 密码
'DB_PORT' => '3306', // 端口
'DB_FIELDS_CACHE' => true, // 启用字段缓存
'URL_MODEL' => 0,// 0 普通模式, 1, pathinfo模式 ,2. rewirte模式 3. 兼容模式
'SHOW_PAGE_TRACE' => true, //打开Trace Page 调试页
// 'TMPL_ENGINE_TYPE' =>'smarty'
);
--------------------**********--------------------------***------------<br>
数据库 user.sql
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50524
Source Host : 127.0.0.1:3306
Source Database : thinkphp0421
Target Server Type : MYSQL
Target Server Version : 50524
File Encoding : 65001
Date: 2014-06-22 11:57:20
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
`age` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '刘备', '27');
INSERT INTO `user` VALUES ('2', '关羽', '26');
INSERT INTO `user` VALUES ('3', '张飞', '25');
INSERT INTO `user` VALUES ('4', '赵云', '24');
INSERT INTO `user` VALUES ('5', '黄忠', '23');
INSERT INTO `user` VALUES ('6', '马超', '22');
INSERT INTO `user` VALUES ('7', '魏延', '21');
INSERT INTO `user` VALUES ('8', '1111', '111');
----*-------------------------------*-----<br>
1. /tp-ceshi/Application/Home/View/User/index.html
<html>
<head>
<title> </title>
</head>
<body>
<table border="1">
<tr height="30">
<th>序号</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<?php
foreach($rows as $row):
?>
<tr height="30">
<th><?php echo $row['id']; ?></th>
<th><?php echo $row['name']; ?></th>
<th><?php echo $row['age']; ?></th>
</tr>
<?php
endforeach;
?>
</table>
</body>
</html>
-*---------------------------------*----<br>
2. /tp-ceshi/Application/Common/Conf/config.php
<?php
return array(
// 配置数据库
'DB_TYPE' => 'mysql',
'DB_HOST'=>'127.0.0.1',
'DB_NAME'=>'user',
'DB_USER'=>'root',
'DB_PWD'=>'root',
//'LOAD_EXT_CONFIG' => 'user,upload', //加载扩展配置
//'ACTION_SUFFIX' => 'Action' , //操作方法后醉
// 设置默认的模块
//'DEFAULT_MODULE' => 'web',
'URL_MODEL' => 2,
'URL_PARAMS_BIND' => true,
'URL_HTML_SUFFIX' => 'html'
);
----*------------------------------*---<br>
3. /tp-ceshi/Application/Home/Controller/UserController.class.php
<?php
// 本类由系统自动生成,仅供测试用途
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller { //查看代码
public function index(){
// 'ds';
//>>> 1.创建User模型对象
$userModel = new \Home\Model\UserModel();
//>> 2.使用模型对象中的查询功能
$rows = $userModel->select(); //二维数组
//》》 3.分配查询出来的数据让视图显示
$this->assign('rows',$rows);
//》》 4.选择视图
$this->display('index');
}
}
*-----*---------------------------------------<br>
1.配置
<?php
return array(
//'配置项'=>'配置值'
'DEFAULT_MODULE' => 'Admin', // 默认模块
'DEFAULT_CONTROLLER' => 'Index', // 默认控制器名称
'DEFAULT_ACTION' => 'index', // 默认操作名称
'DB_TYPE' => 'mysqli', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'thinkphp0421', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => 'root', // 密码
'DB_PORT' => '3306', // 端口
'DB_FIELDS_CACHE' => true, // 启用字段缓存
'URL_MODEL' => 0,// 0 普通模式, 1, pathinfo模式 ,2. rewirte模式 3. 兼容模式
'SHOW_PAGE_TRACE' => true, //打开Trace Page 调试页
// 'TMPL_ENGINE_TYPE' =>'smarty'
);
--------------------**********--------------------------***------------<br>
数据库 user.sql
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50524
Source Host : 127.0.0.1:3306
Source Database : thinkphp0421
Target Server Type : MYSQL
Target Server Version : 50524
File Encoding : 65001
Date: 2014-06-22 11:57:20
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
`age` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '刘备', '27');
INSERT INTO `user` VALUES ('2', '关羽', '26');
INSERT INTO `user` VALUES ('3', '张飞', '25');
INSERT INTO `user` VALUES ('4', '赵云', '24');
INSERT INTO `user` VALUES ('5', '黄忠', '23');
INSERT INTO `user` VALUES ('6', '马超', '22');
INSERT INTO `user` VALUES ('7', '魏延', '21');
INSERT INTO `user` VALUES ('8', '1111', '111');
----*-------------------------------*-----<br>
1. /tp-ceshi/Application/Home/View/User/index.html
<html>
<head>
<title> </title>
</head>
<body>
<table border="1">
<tr height="30">
<th>序号</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<?php
foreach($rows as $row):
?>
<tr height="30">
<th><?php echo $row['id']; ?></th>
<th><?php echo $row['name']; ?></th>
<th><?php echo $row['age']; ?></th>
</tr>
<?php
endforeach;
?>
</table>
</body>
</html>
-*---------------------------------*----<br>
2. /tp-ceshi/Application/Common/Conf/config.php
<?php
return array(
// 配置数据库
'DB_TYPE' => 'mysql',
'DB_HOST'=>'127.0.0.1',
'DB_NAME'=>'user',
'DB_USER'=>'root',
'DB_PWD'=>'root',
//'LOAD_EXT_CONFIG' => 'user,upload', //加载扩展配置
//'ACTION_SUFFIX' => 'Action' , //操作方法后醉
// 设置默认的模块
//'DEFAULT_MODULE' => 'web',
'URL_MODEL' => 2,
'URL_PARAMS_BIND' => true,
'URL_HTML_SUFFIX' => 'html'
);
----*------------------------------*---<br>
3. /tp-ceshi/Application/Home/Controller/UserController.class.php
<?php
// 本类由系统自动生成,仅供测试用途
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller { //查看代码
public function index(){
// 'ds';
//>>> 1.创建User模型对象
$userModel = new \Home\Model\UserModel();
//>> 2.使用模型对象中的查询功能
$rows = $userModel->select(); //二维数组
//》》 3.分配查询出来的数据让视图显示
$this->assign('rows',$rows);
//》》 4.选择视图
$this->display('index');
}
}
*-----*---------------------------------------<br>