本文整理汇总了PHP中CDatabase::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP CDatabase::getInstance方法的具体用法?PHP CDatabase::getInstance怎么用?PHP CDatabase::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDatabase
的用法示例。
在下文中一共展示了CDatabase::getInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterCanAddRole
/**
* 可添加的角色组
*/
public function filterCanAddRole($list)
{
$userData = CSession::get('user');
$groupId = $userData['groupData']['gid'];
// 超级管理员给全部资源
if (1 == $groupId) {
return $list;
}
$category = CDatabase::getInstance()->from('admin_group')->select()->execute()->asArray();
foreach ($category as $key => $val) {
$category[$key]['name'] = $val['gname'];
$category[$key]['id'] = $val['gid'];
}
$category = TreeClass::getTree($category);
// 获取其子类
$childData = $childDataVal = array();
TreeClass::getCatTree($groupId, $category, $childData, $childDataVal);
foreach ($list as $key => $val) {
if (!in_array($val['gid'], $childData)) {
unset($list[$key]);
}
}
return $list;
}
示例2: getGroupList
/**
* 获取所有用户名 以gid排序
*/
public function getGroupList()
{
return CDatabase::getInstance()->from($this->tableName())->select()->execute()->getKey('gid');
}
示例3: delete
/**
* 删除记录
*/
public function delete($where)
{
try {
$tableName = $this->tableName();
$data = CDatabase::getInstance()->delete()->from($tableName)->where($where)->execute();
return $data->isSuccess();
} catch (CDbException $e) {
$this->_lastError = $e->getMessage();
return false;
}
}
示例4: Action_userList
/**
* 用户管理
*/
public function Action_userList()
{
$where['gid'] = $this->Args('gid', 'int');
$where['username'] = $this->Args('username');
// 用户
$list = CDatabase::getInstance()->from('admin_user')->select()->limit(50000);
if (!empty($where['gid']) && $where['gid'] != '-1') {
$list = $list->where('groupId', '=', $where['gid']);
}
if (!empty($where['username'])) {
$list = $list->where('username', 'LIKE', '%' . $where['username'] . '%');
}
$list = $list->execute()->asArray();
// 过滤用户
$list = CModel::factory('adminUserModel')->filterUser($list);
// 组
$group = CModel::factory('adminRoleModel')->findAll()->asArray();
$groupKeyArr = array();
foreach ($group as $val) {
$groupKeyArr[$val['gid']] = $val;
}
$canGroup = CModel::factory('adminRoleModel')->findAll()->asArray();
$canGroup = CModel::factory('adminRoleModel')->filterCanAddRole($group);
$this->assign('where', $where);
$this->assign('canGroup', $canGroup);
$this->assign('list', $list);
$this->assign('group', $groupKeyArr);
$this->display();
}
示例5: filterUser
/**
* 过滤权限
*/
public function filterUser($list)
{
$userData = CSession::get('user');
$groupId = $userData['groupData']['gid'];
if (1 == $groupId) {
return $list;
}
$category = CDatabase::getInstance()->from('admin_group')->select()->execute()->asArray();
foreach ($category as $key => $val) {
$category[$key]['name'] = $val['gname'];
$category[$key]['id'] = $val['gid'];
}
$category = TreeClass::getTree($category);
// 获取该组ID阔以查看的所有子组ID
$childData = $childDataVal = array();
TreeClass::getCatTree($groupId, $category, $childData, $childDataVal);
// 可以查询的子组ID序列
$groupList = array();
foreach ($childDataVal as $key => $val) {
$groupList[] = $val['gid'];
}
foreach ($list as $key => $val) {
if (!in_array($val['groupId'], $groupList)) {
unset($list[$key]);
}
}
return $list;
}
示例6: getCount
public function getCount($setWhere)
{
$list = CDatabase::getInstance()->from($this->tableName())->select(array("count(`{$this->pkName()}`)" => 'num'));
// 筛选条件
$list = $this->setWhere($list, $setWhere);
$list = $list->execute()->current();
return isset($list['num']) ? $list['num'] : 0;
}