后台批量操作bug修复

内核更新
This commit is contained in:
2016-07-11 12:03:55 +08:00
parent 195ec9417c
commit 6460d64ceb
19 changed files with 119 additions and 128 deletions

View File

@@ -40,10 +40,10 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
return empty($this->items);
}
public function toArray($allow = [])
public function toArray()
{
return array_map(function ($value) {
return ($value instanceof Model || $value instanceof self) ? $value->toArray($allow) : $value;
return ($value instanceof Model || $value instanceof self) ? $value->toArray() : $value;
}, $this->items);
}
@@ -225,11 +225,11 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
$result = [];
foreach ($this->items as $row) {
$key = $value = null;
$key = $value = null;
$keySet = $valueSet = false;
if (null !== $index_key && array_key_exists($index_key, $row)) {
$keySet = true;
$key = (string) $row[$index_key];
$key = (string)$row[$index_key];
}
if (null === $column_key) {
$valueSet = true;
@@ -344,13 +344,12 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
/**
* 转换当前数据集为JSON字符串
* @access public
* @param array $allow 允许输出的属性列表
* @param integer $options json参数
* @param integer $options json参数
* @return string
*/
public function toJson($allow = [], $options = JSON_UNESCAPED_UNICODE)
public function toJson($options = JSON_UNESCAPED_UNICODE)
{
return json_encode($this->toArray($allow), $options);
return json_encode($this->toArray(), $options);
}
public function __toString()
@@ -369,6 +368,6 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
if ($items instanceof self) {
return $items->all();
}
return (array) $items;
return (array)$items;
}
}

View File

@@ -62,6 +62,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 字段属性
protected $field = [];
// 显示属性
protected $visible = [];
// 隐藏属性
protected $hidden = [];
// 追加属性
@@ -469,35 +471,46 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
return $this;
}
/**
* 设置需要输出的属性
* @param array $visible
* @return $this
*/
public function visible($visible = [])
{
$this->visible = $visible;
return $this;
}
/**
* 转换当前模型对象为数组
* @access public
* @param array $allow 允许输出的属性列表
* @return array
*/
public function toArray($allow = [])
public function toArray()
{
$item = [];
if (empty($allow)) {
$allow = array_keys($this->data);
}
$allow = array_diff($allow, $this->hidden);
foreach ($this->data as $key => $val) {
// 属性过滤输出
if (!in_array($key, $allow)) {
continue;
}
//过滤属性
if (!empty($this->visible)) {
$data = array_intersect_key($this->data, array_flip($this->visible));
} elseif (!empty($this->hidden)) {
$data = array_diff_key($this->data, array_flip($this->hidden));
} else {
$data = $this->data;
}
foreach ($data as $key => $val) {
if ($val instanceof Model || $val instanceof Collection) {
// 关联模型对象
$item[$key] = $val->toArray();
} elseif (is_array($val) && reset($val) instanceof Model) {
// 关联模型数据集
$data = [];
$arr = [];
foreach ($val as $k => $value) {
$data[$k] = $value->toArray();
$arr[$k] = $value->toArray();
}
$item[$key] = $data;
$item[$key] = $arr;
} else {
// 模型属性
$item[$key] = $this->getAttr($key);
@@ -515,13 +528,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/**
* 转换当前模型对象为JSON字符串
* @access public
* @param array $allow 允许输出的属性列表
* @param integer $options json参数
* @return string
*/
public function toJson($allow = [], $options = JSON_UNESCAPED_UNICODE)
public function toJson($options = JSON_UNESCAPED_UNICODE)
{
return json_encode($this->toArray($allow), $options);
return json_encode($this->toArray(), $options);
}
/**

View File

@@ -19,9 +19,6 @@ use think\Route;
class Url
{
// 生成URL地址的root
protected static $root;
/**
* URL生成 支持路由反射
* @param string $url URL表达式
@@ -116,7 +113,7 @@ class Url
// 检测域名
$domain = self::parseDomain($url, $domain);
// URL组装
$url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/');
$url = $domain . Request::instance()->root() . '/' . ltrim($url, '/');
return $url;
}
@@ -319,11 +316,4 @@ class Url
{
Cache::rm('think_route_map');
}
// 指定当前生成URL地址的root
public static function root($root)
{
self::$root = $root;
Request::instance()->root($root);
}
}
}

View File

@@ -51,7 +51,7 @@ class Collection extends \think\Collection
return $this->paginator;
}
public function toArray($allow = [])
public function toArray()
{
if ($this->paginator) {
try {
@@ -64,10 +64,10 @@ class Collection extends \think\Collection
'total' => $total,
'per_page' => $this->listRows(),
'current_page' => $this->currentPage(),
'data' => parent::toArray($allow)
'data' => parent::toArray()
];
} else {
return parent::toArray($allow);
return parent::toArray();
}
}