mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-10 00:22:48 +08:00
改进代码
This commit is contained in:
@@ -90,6 +90,50 @@ class Query
|
|||||||
return $this->connection;
|
return $this->connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定默认的数据表名(不含前缀)
|
||||||
|
* @access public
|
||||||
|
* @param string $name
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function name($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定默认数据表名(含前缀)
|
||||||
|
* @access public
|
||||||
|
* @param string $table 表名
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTable($table)
|
||||||
|
{
|
||||||
|
$this->table = $table;
|
||||||
|
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
|
* @access public
|
||||||
@@ -761,11 +805,8 @@ class Query
|
|||||||
public function paginate($listRows = null, $simple = false, $config = [])
|
public function paginate($listRows = null, $simple = false, $config = [])
|
||||||
{
|
{
|
||||||
$config = array_merge(Config::get('paginate'), $config);
|
$config = array_merge(Config::get('paginate'), $config);
|
||||||
|
|
||||||
$listRows = $listRows ?: $config['list_rows'];
|
$listRows = $listRows ?: $config['list_rows'];
|
||||||
|
|
||||||
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
|
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
|
||||||
|
|
||||||
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([
|
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([
|
||||||
$class,
|
$class,
|
||||||
'getCurrentPage',
|
'getCurrentPage',
|
||||||
@@ -780,59 +821,15 @@ class Query
|
|||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$total = $this->count();
|
$total = $this->count();
|
||||||
$results = $this->options($options)->page($page, $listRows)->select();
|
$results = $this->options($options)->page($page, $listRows)->select();
|
||||||
$paginator = new $class($results, $listRows, $page, $simple, $total, $config);
|
|
||||||
} else {
|
} else {
|
||||||
$results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
|
$results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
|
||||||
$paginator = new $class($results, $listRows, $page, $simple, null, $config);
|
$total = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$paginator = new $class($results, $listRows, $page, $simple, $total, $config);
|
||||||
return $paginator->items();
|
return $paginator->items();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定默认的数据表名(不含前缀)
|
|
||||||
* @access public
|
|
||||||
* @param string $name
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function name($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定默认数据表名(含前缀)
|
|
||||||
* @access public
|
|
||||||
* @param string $table 表名
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setTable($table)
|
|
||||||
{
|
|
||||||
$this->table = $table;
|
|
||||||
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
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user