thinphp3.2 表格案例

配置
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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值