修正模型类的saveAll方法 db助手函数增加name参数

This commit is contained in:
thinkphp
2016-05-02 14:24:11 +08:00
parent 46e1d8dc17
commit e41120dcbf
2 changed files with 7 additions and 5 deletions

View File

@@ -152,12 +152,13 @@ function model($name = '', $layer = MODEL_LAYER)
/** /**
* 实例化数据库类 * 实例化数据库类
* @param array $config 数据库配置参数 * @param string $name 操作的数据表名称(不含前缀)
* @param array|string $config 数据库配置参数
* @return \think\db\Connection * @return \think\db\Connection
*/ */
function db($config = []) function db($name = '', $config = [])
{ {
return Db::connect($config); return Db::connect($config)->name($name);
} }
/** /**

View File

@@ -205,9 +205,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
* @access public * @access public
* @param array $data 数据 * @param array $data 数据
* @param array $where 更新条件 * @param array $where 更新条件
* @param bool $getId 新增的时候是否获取id
* @return integer * @return integer
*/ */
public function save($data = [], $where = []) public function save($data = [], $where = [], $getId = true)
{ {
if (!empty($data)) { if (!empty($data)) {
// 数据对象赋值 // 数据对象赋值
@@ -270,7 +271,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$result = self::db()->insert($this->data); $result = self::db()->insert($this->data);
// 获取自动增长主键 // 获取自动增长主键
if ($result) { if ($result && $getId) {
$insertId = self::db()->getLastInsID(); $insertId = self::db()->getLastInsID();
$pk = $this->getPk(); $pk = $this->getPk();
if (is_string($pk) && $insertId) { if (is_string($pk) && $insertId) {