改进Model类的getData方法

This commit is contained in:
thinkphp
2016-05-18 11:01:49 +08:00
parent 198ea76923
commit fdd41cd1c7
2 changed files with 21 additions and 21 deletions

View File

@@ -163,7 +163,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/
public function getData($name = '')
{
return isset($this->data[$name]) ? $this->data[$name] : $this->data;
return array_key_exists($name, $this->data) ? $this->data[$name] : $this->data;
}
/**

View File

@@ -797,6 +797,26 @@ class Query
return $this;
}
/**
* 得到当前的数据表
* @access public
* @param string $name
* @return string
*/
public function getTable($name = '')
{
if ($name || empty($this->table)) {
$name = $name ?: $this->name;
$tableName = $this->connection->getConfig('prefix');
if ($name) {
$tableName .= Loader::parseName($name);
}
} else {
$tableName = $this->table;
}
return $tableName;
}
/**
* 指定当前操作的数据表
* @access public
@@ -1038,26 +1058,6 @@ class Query
return $this;
}
/**
* 得到当前的数据表
* @access public
* @param string $name
* @return string
*/
public function getTable($name = '')
{
if ($name || empty($this->table)) {
$name = $name ?: $this->name;
$tableName = $this->connection->getConfig('prefix');
if ($name) {
$tableName .= Loader::parseName($name);
}
} else {
$tableName = $this->table;
}
return $tableName;
}
/**
* 获取数据表信息
* @access public