修正Model类和Config类

This commit is contained in:
thinkphp
2016-05-13 22:18:24 +08:00
parent aaa0fd7c9f
commit 90b86c684c
2 changed files with 13 additions and 11 deletions

View File

@@ -62,7 +62,7 @@ class Config
APP_DEBUG && Log::record('[ CONFIG ] ' . $file, 'info');
$type = pathinfo($file, PATHINFO_EXTENSION);
if ('php' != $type) {
return self::parse($config, $type, $name, $range);
return self::parse($file, $type, $name, $range);
} else {
return self::set(include $file, $name, $range);
}

View File

@@ -90,8 +90,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
* 架构函数
* @access public
* @param array|object $data 数据
* @param bool $init 是否需要初始化
*/
public function __construct($data = [])
public function __construct($data = [], $init = true)
{
if (is_object($data)) {
$this->data = get_object_vars($data);
@@ -101,10 +102,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if (empty($this->name)) {
$this->name = basename(str_replace('\\', '/', get_class($this)));
}
// 获取字段类型信息并缓存
$this->fieldType = self::db()->getTableInfo('', 'type');
$this->initialize();
$this->relation = new Relation($this);
if ($init) {
// 获取字段类型信息并缓存
$this->fieldType = self::db()->getTableInfo('', 'type');
$this->initialize();
$this->relation = new Relation($this);
}
}
/**
@@ -256,7 +259,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if (!empty($data)) {
// 数据对象赋值
foreach ($data as $key => $value) {
$this->__set($key, $value, $data);
$this->__set($key, $value);
}
if (!empty($where)) {
$this->isUpdate = true;
@@ -869,7 +872,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$model = get_called_class();
if (!isset(self::$links[$model])) {
$class = new static;
$class = new static([], false);
self::$links[$model] = Db::connect($class->connection);
self::$instance[$model] = $class;
} else {
@@ -914,10 +917,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
* @access public
* @param string $name 名称
* @param mixed $value 值
* @param array $data 数据信息
* @return void
*/
public function __set($name, $value, $data = [])
public function __set($name, $value)
{
if (is_null($value) && in_array($name, $this->autoTimeField)) {
// 自动写入的时间戳字段
@@ -944,7 +946,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 检测修改器
$method = 'set' . Loader::parseName($name, 1) . 'Attr';
if (method_exists($this, $method)) {
$value = $this->$method($value, array_merge($data, $this->data));
$value = $this->$method($value, $this->data);
} elseif (isset($this->type[$name])) {
// 类型转换
$type = $this->type[$name];