本文整理汇总了PHP中think\Db::name方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::name方法的具体用法?PHP Db::name怎么用?PHP Db::name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Db
的用法示例。
在下文中一共展示了Db::name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logs
/**
* 记录用户日志
* @param string $logs 用户日志
* @param array $data 操作的数据
* @param boolean $autoUid 自动获取用户UID 否则传入UID
*/
function logs($logs, $data = [], $autoUid = true)
{
$uid = $autoUid === true ? UID : $autoUid;
$data = !empty($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : '';
$data = ['uid' => $uid, 'logs' => $logs, 'datas' => $data, 'create_time' => NOW_TIME];
Db::name('Logs')->insert($data);
}
示例2: checkExtends
/**
* 检测继承分类是否是相同的模型
* @param [type] $value [description]
* @param [type] $rule [description]
* @param [type] $data [description]
* @return [type] [description]
*/
protected function checkExtends($value, $rule, $data)
{
if (0 != $data['pid']) {
return $value == Db::name('Category')->where('id', $data['pid'])->value('model');
} else {
return true;
}
}
示例3: checkNode
/**
* 验证菜单是几级节点
* @param [type] $value [description]
* @param [type] $rule [description]
* @param [type] $data [description]
* @return [type] [description]
*/
protected function checkNode($pid, $rule, $data)
{
// 一级菜单最多三个
if ($pid == 0) {
return Db::name('WechatMenu')->where('pid', 0)->count() >= 3 ? '一级菜单数量最多三个' : true;
} else {
return Db::name('WechatMenu')->where('pid', $pid)->count() >= 5 ? '二级菜单数量最多五个' : true;
}
}
示例4: autoLogin
/**
* 保存登陆信息
* @param [type] $user
*/
private function autoLogin($user)
{
$loginData = ['uid' => $user['id'], 'account' => $user['account'], 'login' => $user['login'], 'last_time' => $user['last_time'], 'last_ip' => $user['last_ip']];
session('user_auth', $loginData);
session('user_auth_sign', data_auth_sign($loginData));
// 保存登陆信息
$saveData = ['last_ip' => get_client_ip(), 'last_time' => NOW_TIME, 'login' => ['exp', '`login`+1']];
Db::name('Member')->where('id', $user['id'])->update($saveData);
logs('登陆成功', '', $user['id']);
}
示例5: treeSelect
/**
* 返回树形选择
* @param string 分类模型
* @param integer $unShowId 排除显示的节点
* @return array
*/
public function treeSelect($model = '', $unShowId = 0)
{
$map['status'] = 1;
if ($unShowId) {
$map['id'] = ['neq', $unShowId];
}
if ($model) {
$map['model'] = $model;
}
$categorys = Db::name('category')->where($map)->order('sort asc')->select();
return Tree::toFormatTree($categorys);
}
示例6: index
/**
* 上传文件管理
*/
public function index($type = '')
{
$total = disk_total_space(".");
$this->assign('disk_use', round(($total - disk_free_space(".")) / $total * 100, 2));
$map = [];
if ($type) {
$map['type'] = $type;
}
$list = parent::_list('Storage', $map);
$this->assign('list', $list);
$this->assign('size', Db::name('Storage')->where($map)->sum('size'));
$this->assign('types', Db::name('Storage')->field('type')->distinct('type')->select());
return $this->fetch();
}
示例7: getMenuIds
/**
* 获取用户菜单节点Id集合
* @param [type] $uid 用户UID
* @return array
*/
public static function getMenuIds($uid)
{
$gIds = self::getGroupIds($uid);
$menuIds = '';
if ($gIds) {
$menuIds = Db::name('Auth')->where('id', 'in', $gIds)->column('rules');
$menuIds = implode($menuIds, ',');
$menuIds = trim($menuIds, ',');
}
$openMap = ['status' => 2, 'auth' => 0];
$openMenus = Db::name('Menu')->where($openMap)->column('id');
$openMenus = implode($openMenus, ',');
if (!empty($openMenus)) {
$menuIds .= ',' . $openMenus;
}
return trim($menuIds, ',');
}
示例8: password
/**
* 修改密码
*/
public function password()
{
if (IS_POST) {
$data = $this->request->post();
$validate = Loader::validate('Member');
if (!$validate->scene('changepass')->check($data)) {
return $this->error($validate->getError());
}
$passData = ['password' => umd5($data['newpass']), 'update_time' => NOW_TIME];
if (Db::name('Member')->where('id', UID)->update($passData)) {
return $this->success('密码修改成功');
} else {
return $this->error();
}
} else {
return $this->fetch();
}
}
示例9: load
/**
* 加载系统扩展配置
*/
public static function load()
{
$config = \think\Cache::get('db_config_cache_data');
if (!$config) {
// 在这里先判断一下数据库是否已经正确安装
$Db = \think\Loader::db();
$Query = $Db->query("SHOW TABLES LIKE '" . \think\Config::get('database.prefix') . "config'");
if (empty($Query)) {
self::install();
}
$data = \think\Db::name('Config')->where('status', 1)->field('type,name,value')->select();
$config = [];
if ($data && is_array($data)) {
foreach ($data as $value) {
$config[$value['name']] = self::parse($value['type'], $value['value']);
}
}
\think\Cache::set('db_config_cache_data', $config);
}
\think\Config::set($config);
}
示例10: sort
/**
* 快速修改状态
*/
public function sort($pid)
{
if (IS_POST) {
$sort = $this->request->post('sort/a');
if (empty($sort)) {
return $this->error();
}
foreach ($sort as $key => $id) {
Db::name('Category')->where('id', $id)->setField('sort', $key + 1);
}
return $this->success('操作成功', Url('system/category/index') . '?pid=' . $pid);
} else {
$map = ['pid' => $pid, 'status' => 1];
$list = Db::name('Category')->where($map)->order('sort asc')->select();
$this->assign('list', $list);
return $this->fetch();
}
}
示例11: _list
/**
* 通用分页列表数据集获取方法
* 如果表单字段有 status 默认会查询 status > 0 的数据
* @param sting|Model $model 模型名或模型实例
* @param array $where where查询条件(优先级: $where>模型设定)
* @param array|string $order 排序条件,传入null时使用sql默认排序或模型属性(优先级最高);
* 否则使用$order参数(如果$order参数,且模型也没有设定过order,则取主键降序);
* @param boolean $field 单表模型用不到该参数,要用在多表join时为field()方法指定参数
* @param integer $listRows 分页条数
* @return array|false
* 返回数据集
*/
protected final function _list($model, $where = [], $order = null, $field = true, $listRows = 20)
{
if (is_string($model)) {
$table = Db::name($model);
} else {
$table = $model;
}
$tableInfo = $table->getTableInfo();
$fields = $tableInfo['fields'];
$_order = $this->request->get('_order');
if (!is_null($_order) && in_array($_order, $fields)) {
$order = $_order . ' desc';
} elseif (is_null($order) && !empty($tableInfo['pk'])) {
$order = $tableInfo['pk'] . ' desc';
}
// 设置默认查询 status > 0 的数据
if (empty($where) && in_array('status', $fields)) {
$where['status'] = ['egt', 0];
}
$config = ['type' => 'tools\\Pager', 'list_rows' => $listRows, 'query' => $this->request->get()];
$list = $table->field($field)->where($where)->order($order)->paginate(null, false, $config);
$this->_page = $list->render();
$this->_total = $list->total();
return $list;
}
示例12: clear
/**
* 清空回收站
* @param [integer] $id
*/
public function clear($id = '')
{
if (is_numeric($id)) {
$map['id'] = $id;
}
$map['status'] = -1;
$data = ['status' => -2, 'update_time' => NOW_TIME];
if (Db::name('Article')->where($map)->update($data)) {
return $this->success();
} else {
return $this->error();
}
}
示例13: lists
/**
* 获取我的好友关系列表
* @param integer $uid [description]
* @param integer $type 1 关注列表,2 被关注 3 好友
* @return array 用户ID集合
*/
public static function lists($uid, $type = 1, $page = 1, $rows = 10)
{
$model = Db::name('Friend');
switch ($type) {
case 1:
$result = $model->where('type IN (1,3) AND uid=' . $uid)->whereOr('type IN (2,3) AND fid=' . $uid)->page($page, $rows)->select();
break;
case 2:
$result = $model->where('type IN (2,3) AND uid=' . $uid)->whereOr('type IN (1,3) AND fid=' . $uid)->page($page, $rows)->select();
break;
case 3:
$result = $model->where('type=3 AND uid=' . $uid)->whereOr('type=3 AND fid=' . $uid)->page($page, $rows)->select();
break;
}
$ids = [];
foreach ($result as $key => $value) {
if ($value['uid'] == $uid) {
array_push($ids, $value['fid']);
} else {
array_push($ids, $value['uid']);
}
}
return $ids;
}
示例14: index
public function index()
{
$data = Db::name('system_config')->find();
return json($data);
}
示例15: belongsToMany
/**
* BELONGS TO MANY 关联定义
* @access public
* @param string $model 模型名
* @param string $table 中间表名
* @param string $foreignKey 关联外键
* @param string $localKey 当前模型关联键
* @return \think\db\Query|string
*/
public function belongsToMany($model, $table = '', $foreignKey = '', $localKey = '')
{
// 记录当前关联信息
$model = $this->parseModel($model);
$name = Loader::parseName(basename(str_replace('\\', '/', $model)));
$table = $table ?: Db::name(Loader::parseName($this->name) . '_' . $name)->getTable();
$foreignKey = $foreignKey ?: $name . '_id';
$localKey = $localKey ?: Loader::parseName($this->name) . '_id';
return $this->relation()->belongsToMany($model, $table, $foreignKey, $localKey);
}