关联模型最佳实践

浏览:2186 发布日期:2015/01/23 分类:用法示例 关键字: 关联模型
演示ThinkPHP关联模型使用方法
TP3.2.3已经基本支持了关联模型的CURD。
基本能投入使用,所以写了这个实例。

步骤: 解压文件夹到www目录
绑定测试域名到www/thinkphp/Public
(一定注意,是绑定到Public目录而不是根目录)
如果是linux,设置权限 chmod -R 777 www/thinkphp/Data/RunTime
导入数据库文件:www/thinkphp/Data/DB/thinkphp.sql到数据库
编辑www/thinkphp/App/Common/Conf/config.php配置数据库连接信息
浏览器访问测试域名,输出数据如下:array(2) {
  [0] => array(7) {
    ["id"] => string(1) "1"
    ["name"] => string(7) "shellus"
    ["email"] => string(0) ""
    ["tel"] => string(0) ""
    ["nick"] => string(0) ""
    ["password"] => string(16) "shellus的密码"
    ["document"] => array(2) {
      [0] => array(2) {
        ["title"] => string(31) "shellus的第一篇测试文章"
        ["content"] => string(40) "shellus的第一篇测试文章的内容"
      }
      [1] => array(2) {
        ["title"] => string(31) "shellus的第二篇测试文章"
        ["content"] => string(40) "shellus的第二篇测试文章的内容"
      }
    }
  }
  [1] => array(7) {
    ["id"] => string(1) "2"
    ["name"] => string(12) "娃娃脾气"
    ["email"] => string(0) ""
    ["tel"] => string(0) ""
    ["nick"] => string(0) ""
    ["password"] => string(15) "娃娃的密码"
    ["document"] => array(3) {
      [0] => array(2) {
        ["title"] => string(36) "娃娃脾气的第一篇测试文章"
        ["content"] => string(45) "娃娃脾气的第一篇测试文章的内容"
      }
      [1] => array(2) {
        ["title"] => string(36) "娃娃脾气的第二篇测试文章"
        ["content"] => string(45) "娃娃脾气的第二篇测试文章的内容"
      }
      [2] => array(2) {
        ["title"] => string(36) "娃娃脾气的第三篇测试文章"
        ["content"] => string(45) "娃娃脾气的第三篇测试文章的内容"
      }
    }
  }
}
见:http://test.endaosi.com:8110/

欢迎提问。

附件 demo.zip ( 2.51 MB 下载:114 次 )

评论( 相关
后面还有条评论,点击查看>>