<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
define('HAS_ONE',1);
define('BELONGS_TO',2);
define('HAS_MANY',3);
define('MANY_TO_MANY',4);
define('MUST_TO_VALIDATE',1); // 必须验证
define('EXISTS_TO_VAILIDATE',0); // 表单存在字段则验证
define('VALUE_TO_VAILIDATE',2); // 表单值不为空则验证
/**
+------------------------------------------------------------------------------
* ThinkPHP Model模型类 抽象类
* 实现了ORM和ActiveRecords模式
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Core
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class Model extends Base implements IteratorAggregate
{
// 数据库连接对象列表
protected $_db = array();
// 当前数据库操作对象
protected $db = null;
// 数据表前缀
protected $tablePrefix = '';
// 数据表后缀
protected $tableSuffix = '';
// 模型名称
protected $name = '';
// 数据库名称
protected $dbName = '';
// 数据表名(不包含表前缀)
protected $tableName = '';
// 实际数据表名(包含表前缀)
protected $trueTableName ='';
// 字段信息
protected $fields = array();
// 字段类型信息
protected $type = array();
// 数据信息
protected $data = array();
// 查询表达式参数
protected $options = array();
// 数据列表信息
protected $dataList = array();
// 上次错误信息
protected $error = '';
// 验证错误信息
protected $validateError = array();
// 包含的聚合对象
protected $aggregation = array();
// 是否为复合对象
protected $composite = false;
// 是否为视图模型
protected $viewModel = false;
// 乐观锁
protected $optimLock = 'lock_version';
// 悲观锁
protected $pessimisticLock = false;
protected $autoSaveRelations = false; // 自动关联保存
protected $autoDelRelations = false; // 自动关联删除
protected $autoAddRelations = false; // 自动关联写入
protected $autoReadRelations = false; // 自动关联查询
protected $lazyQuery = false; // 是否启用惰性查询
// 自动写入时间戳
protected $autoCreateTimestamps = array('create_at','create_on','cTime');
protected $autoUpdateTimestamps = array('update_at','update_on','mTime');
protected $autoTimeFormat = '';
protected $blobFields = null;
protected $blobValues = null;
/**
+----------------------------------------------------------
* 架构函数
* 取得DB类的实例对象 数据表字段检查
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param mixed $data 要创建的数据对象内容
+----------------------------------------------------------
*/
public function __construct($data='')
{
// 模型初始化
$this->_initialize();
// 模型名称获取
$this->name = $this->getModelName();
// 如果不是复合对象进行数据库初始化操作
if(!$this->composite) {
import("Think.Db.Db");
// 获取数据库操作对象
if(!empty($this->connection)) {
// 当前模型有独立的数据库连接信息
$this->db = Db::getInstance($this->connection);
}else{
$this->db = Db::getInstance();
}
// 设置数据库的返回数据格式
$this->db->resultType = C('DATA_RESULT_TYPE');
//为获得ORACLE自增LastID而统一考虑的
$this->db->tableName = $this->parseName($this->name);
// 设置默认的数据库连接
$this->_db[0] = &$this->db;
// 设置表前后缀
$this->tablePrefix = $this->tablePrefix?$this->tablePrefix:C('DB_PREFIX');
$this->tableSuffix = $this->tableSuffix?$this->tableSuffix:C('DB_SUFFIX');
// 数据表字段检测
$this->_checkTableInfo();
}
// 如果有data数据进行实例化,则创建数据对象
if(!empty($data)) {
$this->create($data);
}
}
/**
+----------------------------------------------------------
* 取得模型实例对象
+----------------------------------------------------------
* @static
* @access public
+----------------------------------------------------------
* @return mixed 返回数据模型实例
+----------------------------------------------------------
*/
public static function getInstance()
{
return get_instance_of(__CLASS__);
}
/**
+----------------------------------------------------------
* 设置数据对象的值 (魔术方法)
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 名称
* @param mixed $value 值
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
public function __set($name,$value) {
// 设置数据对象属性
$this->data[$name] = $value;
}
/**
+----------------------------------------------------------
* 获取数据对象的值 (魔术方法)
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 名称
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function __get($name) {
if(isset($this->data[$name])) {
return $this->data[$name];
}elseif(property_exists($this,$name)){
return $this->$name;
}else{
return null;
}
}
/**
+----------------------------------------------------------
* 字符串命名风格转换
* type
* =0 将Java风格转换为C的风格
* =1 将C风格转换为Java的风格
+----------------------------------------------------------
* @access protected
+----------------------------------------------------------
* @param string $name 字符串
* @param integer $type 转换类型
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
protected function parseName($name,$type=0) {
if($type) {
return preg_replace("/_([a-zA-Z])/e", "strtoupper('\\1')", $name);
}else{
$name = preg_replace("/[A-Z]/", "_\\0", $name);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
ThinkPHP是一个免费开源的,快速、简单的面向对象的轻量级PHP开发框架,遵循Apache2开源协议发布,是为了简化企业级应用开发和敏捷WEB应用开发而诞生的。借鉴了国外很多优秀的框架和模式,使用面向对象的开发结构和MVC模式,融合了Struts的Action思想和JSP的TagLib(标签库)、RoR的ORM映射和ActiveRecord模式,封装了CURD和一些常用操作,单一入口模式等,在模版引擎、缓存机制、认证机制和扩展性方面均有独特的表现。 使用ThinkPHP,你可以更方便和快捷的开发和部署应用,当然不仅仅是企业级应用,任何PHP应用开发都可以从ThinkPHP的简单、兼容和快速的特性中受益。简洁、快速和实用是ThinkPHP发展秉承的宗旨,为此ThinkPHP会不断吸收和融入更好的技术以保证其新鲜和活力,提供WEB应用开发的最佳实践! ThinkPHP遵循Apache2开源许可协议发布,意味着你可以免费使用ThinkPHP,甚至允许把你的ThinkPHP应用采用商业闭源发布。
资源推荐
资源详情
资源评论
收起资源包目录
thinkphp php开源框架 (1024个子文件)
thinkphp.BMP 82KB
ThinkPHP快速入门.chm 400KB
ThinkPHP快速入门.chm 400KB
ThinkPHP数据操作指南.chm 122KB
ThinkPHP数据操作指南.chm 122KB
ThinkPHP 基于角色的权限控制.chm 118KB
ThinkPHP 基于角色的权限控制.chm 118KB
ThinkPHP编码规范.chm 89KB
ThinkPHP编码规范.chm 89KB
ThinkPHP 错误调试和日志.chm 77KB
ThinkPHP 错误调试和日志.chm 77KB
ThinkPHP模板指南.chm 73KB
ThinkPHP模板指南.chm 73KB
ThinkPHP常见问题集合.chm 69KB
ThinkPHP常见问题集合.chm 69KB
ThinkPHP配置指南和参考.chm 61KB
ThinkPHP配置指南和参考.chm 61KB
ThinkPHP关联操作.chm 46KB
ThinkPHP关联操作.chm 46KB
ThinkPHP URL设计和SEO支持.chm 44KB
ThinkPHP URL设计和SEO支持.chm 44KB
ThinkPHP类库导入和自动加载.chm 41KB
ThinkPHP类库导入和自动加载.chm 41KB
ThinkPHP执行流程.chm 37KB
ThinkPHP执行流程.chm 37KB
ThinkPHP项目自动生成和编译.chm 36KB
ThinkPHP项目自动生成和编译.chm 36KB
ThinkPHP视图模型.chm 34KB
ThinkPHP视图模型.chm 34KB
ThinkPHP多语言的使用和配置.chm 34KB
ThinkPHP多语言的使用和配置.chm 34KB
ThinkPHP多元化缓存机制.chm 33KB
ThinkPHP多元化缓存机制.chm 33KB
ThinkPHP可配置的静态缓存设计.chm 30KB
ThinkPHP可配置的静态缓存设计.chm 30KB
ThinkPHP表单令牌设计.chm 29KB
ThinkPHP表单令牌设计.chm 29KB
style.css 22KB
style.css 15KB
style.css 15KB
style.css 15KB
common.css 15KB
stylesheet.css 5KB
fck_editor.css 4KB
fck_editorarea.css 3KB
fck_dialog.css 534B
banner.css 393B
fck_internal.css 337B
Thumbs.db 40KB
Thumbs.db 8KB
loading_logo.gif 10KB
fck_strip.gif 4KB
feed_blue.gif 4KB
puke.gif 4KB
comments.gif 3KB
wait.gif 3KB
fear.gif 3KB
horror.gif 2KB
logo_fckeditor.gif 2KB
title_01.gif 2KB
title_01.gif 2KB
title_01.gif 2KB
shy.gif 2KB
image2.gif 1KB
sad.gif 1KB
update.gif 1KB
update.gif 1KB
update.gif 1KB
update.gif 1KB
warn.gif 1KB
warn.gif 1KB
warn.gif 1KB
email.gif 1KB
image.gif 1KB
weather_2s.gif 1KB
icon_entry.gif 1KB
quote.gif 980B
color.gif 949B
bold.gif 928B
code.gif 915B
underline.gif 910B
italic.gif 881B
hr.gif 875B
envy.gif 856B
cry.gif 807B
pig.gif 804B
smile.gif 802B
mute.gif 791B
angry.gif 789B
zzz.gif 788B
wound.gif 788B
flash.gif 782B
ajaxloading.gif 781B
ajaxloading.gif 781B
ajaxloading.gif 781B
ajaxloading.gif 781B
ajaxloading.gif 781B
ajaxloading.gif 781B
coolsmile.gif 780B
astonish.gif 771B
共 1024 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
- doper2013-05-06可以运行的资源
kangshaojun
- 粉丝: 7
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功