修正traits

This commit is contained in:
thinkphp
2016-01-30 23:20:30 +08:00
parent 601a6dc945
commit 5fda023980
3 changed files with 13 additions and 21 deletions

View File

@@ -14,9 +14,6 @@ namespace traits\model;
trait Adv
{
protected $optimLock = 'lock_version';
//protected $serializeField = [];
//protected $readonlyField = [];
//protected $partition = [];
/**
* 利用__call方法重载 实现一些特殊的Model方法 (魔术方法)

View File

@@ -15,9 +15,6 @@ use think\Lang;
trait Auto
{
//protected $validate = []; // 自动验证定义
//protected $auto = []; // 自动完成定义
/**
* 创建数据对象 但不保存到数据库
* @access public
@@ -193,9 +190,9 @@ trait Auto
// 检查填充条件
if ($flags & $type) {
switch (trim($auto[3])) {
case 'function': // 使用函数进行填充 字段的值作为参数
case 'callback': // 使用回调方法
$args = isset($auto[4]) ? (array)$auto[4] : [];
case 'function': // 使用函数进行填充 字段的值作为参数
case 'callback': // 使用回调方法
$args = isset($auto[4]) ? (array) $auto[4] : [];
if (is_string($auto[0]) && strpos($auto[0], ',')) {
$auto[0] = explode(',', $auto[0]);
}
@@ -211,19 +208,19 @@ trait Auto
if ('function' == $auto[3]) {
$data[$auto[0]] = call_user_func_array($auto[1], $args);
} else {
$data[$auto[0]] = call_user_func_array([& $this, $auto[1]], $args);
$data[$auto[0]] = call_user_func_array([ & $this, $auto[1]], $args);
}
break;
case 'field': // 用其它字段的值进行填充
case 'field': // 用其它字段的值进行填充
$data[$auto[0]] = $data[$auto[1]];
break;
case 'ignore': // 为空忽略
case 'ignore': // 为空忽略
if ($auto[1] === $data[$auto[0]]) {
unset($data[$auto[0]]);
}
break;
case 'string':
default: // 默认作为字符串填充
default: // 默认作为字符串填充
$data[$auto[0]] = $auto[1];
}
if (isset($data[$auto[0]]) && false === $data[$auto[0]]) {
@@ -318,18 +315,18 @@ trait Auto
}
$val[3] = isset($val[3]) ? $val[3] : self::EXISTS_VALIDATE;
$val[4] = isset($val[4]) ? $val[4] : 'regex';
$status = true;
$status = true;
// 判断验证条件
switch ($val[3]) {
case self::MUST_VALIDATE: // 必须验证 不管表单是否有设置该字段
case self::MUST_VALIDATE: // 必须验证 不管表单是否有设置该字段
$status = $this->_validationFieldItem($data, $val);
break;
case self::VALUE_VALIDATE: // 值不为空的时候才验证
case self::VALUE_VALIDATE: // 值不为空的时候才验证
if ('' != trim($data[$val[0]])) {
$status = $this->_validationFieldItem($data, $val);
}
break;
default: // 默认表单存在该字段就验证
default: // 默认表单存在该字段就验证
if (isset($data[$val[0]])) {
$status = $this->_validationFieldItem($data, $val);
}
@@ -358,7 +355,7 @@ trait Auto
switch (strtolower(trim($val[4]))) {
case 'function': // 使用函数进行验证
case 'callback': // 调用方法进行验证
$args = isset($val[6]) ? (array)$val[6] : [];
$args = isset($val[6]) ? (array) $val[6] : [];
if (is_string($val[0]) && strpos($val[0], ',')) {
$val[0] = explode(',', $val[0]);
}
@@ -371,7 +368,7 @@ trait Auto
} else {
array_unshift($args, isset($data[$val[0]]) ? $data[$val[0]] : null);
}
return call_user_func_array('function' == $val[4] ? $val[1] : [& $this, $val[1]], $args);
return call_user_func_array('function' == $val[4] ? $val[1] : [ & $this, $val[1]], $args);
case 'confirm': // 验证两个字段是否相同
return $data[$val[0]] == $data[$val[1]];
case 'unique': // 验证某个值是否唯一

View File

@@ -14,8 +14,6 @@ namespace traits\model;
trait View
{
protected $viewFields = [];
/**
* 自动检测数据表信息
* @access protected