Executes the query and returns a single row of result.
public one ( |
||
$db | the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. | |
return | array | boolean | the first row (in terms of an array) of the query result. False is returned if the query results in nothing. |
public function actionCheck_login() { $username = $_POST['username']; $pwd = $_POST['pwd']; $query = new Query(); $query->select(['name', 'status', 'password'])->from('admin')->where(['name' => $username]); $arr = $query->one(); if ($arr) { if ($arr['password'] == md5($pwd)) { $_SESSION['user_id'] = $arr['_id']; $_SESSION['user_name'] = $arr['name']; if ($arr['name'] != "admin") { $userid = $arr['_id']; //根据用户id查找用户的角色ID $query->select(['role_id'])->from('user_role')->where(['user_id' => "{$userid}"]); $res = $query->one(); $role_id = $res['role_id']; //根据角色ID查询所有权限ID,将其ID存入字符串中 $q = new Query(); $q->select(['node_id'])->from('role_node')->where(['role_id' => $role_id]); $ar = $q->all(); $que = new Query(); foreach ($ar as $key => $v) { // $node[$key] = $v['node_id']; $idd = $v['node_id']; $que->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['_id' => "{$idd}"])->andwhere(['n_level' => "1"]); $quan[$key] = $que->all(); } $yi_quan = array_filter($quan); $_SESSION['yi_quan'] = $yi_quan; $quee = new Query(); foreach ($ar as $kk => $vv) { // $node[$key] = $v['node_id']; $iddd = $vv['node_id']; $quee->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['_id' => "{$iddd}"])->andwhere(['n_level' => "2"]); $quanx[$kk] = $quee->all(); } $er_quan = array_filter($quanx); $_SESSION['er_quan'] = $er_quan; } else { $que = new Query(); $que->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['n_level' => "1"]); $yi_quan = $que->all(); $_SESSION['yi_q'] = $yi_quan; $quee = new Query(); $quee->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['n_level' => "2"]); $er_quan = $quee->all(); $_SESSION['er_q'] = $er_quan; } echo "<script>location.href='index.php?r=site/index'</script>"; } else { echo "<script>alert('密码错误');location.href='index.php?r=public/login'</script>"; } } else { echo "<script>alert('用户名或密码错误');location.href='index.php?r=public/login'</script>"; } }
public function actionXiugai() { $id = $_GET['id']; $query = new Query(); $query->select(['email', 'name', 'status'])->from('admin')->where(['_id' => $id]); $rows = $query->one(); return $this->renderPartial('save', compact('rows')); }
public function actionXiugai() { $id = $_GET['id']; $query = new Query(); $query->select(['n_name', 'nickname', 'n_level'])->from('node')->where(['_id' => $id]); $rows = $query->one(); return $this->renderPartial('save', compact('rows')); }
static function GetUserFormsById($id) { $query = new Query(); // compose the query $query->select(['data'])->from('forms')->where(['_id' => $id]); // execute the query $row = $query->one(); return $row; }
/** * @inheritdoc */ public function one($db = null) { $row = parent::one($db); if ($row !== false) { $models = $this->populate([$row]); return reset($models) ?: null; } else { return null; } }
public function actionEdit() { $id = $_GET['id']; $query = new Query(); $query->select(['type_name', 'level', 'p_id'])->from('type')->where(['_id' => $id]); $data['rows'] = $query->one(); $query->select(['type_name', 'level', 'p_id'])->from('type')->where(['p_id' => '0']); $data['arr'] = $query->all(); return $this->renderPartial("edit", $data); }
private function formatCookbookForAPI($cookbook) { //averageScore if (!isset($cookbook['averageScore'])) { $cookbook['averageScore'] = 0.0; } //isNewest for ($i = 0; $i < count($cookbook['type']); $i++) { if ($cookbook['type'][$i] == '最新食譜') { $cookbook['isNewest'] = 'Y'; } else { $cookbook['isNewest'] = 'N'; } } //collection number $cookbookId = $cookbook['cookbookId']; $query = new Query(); $query->from('uhkklpUserCookbook')->where(['cookbookId' => $cookbookId])->andWhere(['collection' => 'Y']); $collectionNumber = $query->count(); $cookbook['collectionNumber'] = $collectionNumber; //score number $cookbookId = $cookbook['cookbookId']; $query = new Query(); $query->from('uhkklpUserCookbook')->where(['cookbookId' => $cookbookId]); $scorerNumber = $query->count(); $cookbook['scorerNumber'] = $scorerNumber; //sample $sample = $cookbook['sample']; for ($j = 0; $j < count($sample); $j++) { $querySample = new Query(); $querySample->from('uhkklpSample')->where(['_id' => $sample[$j]['id']]); $sampleDate = $querySample->one(); $cookbook['sample'][$j]['imgUrl'] = $sampleDate['imgUrl']; $cookbook['sample'][$j]['explain'] = $sampleDate['quantity']; unset($cookbook['sample'][$j]['quantity']); } return $cookbook; }
public function actionAddrole_node() { $role_id = $_POST['role_id']; $quan_id = $_POST['quanxian']; $query = new Query(); $query->select(['_id'])->from('role_node')->where(['node_id' => $quan_id]); $ar = $query->one(); $collection = Yii::$app->mongodb->getCollection('role_node'); if (empty($ar)) { $res = $collection->insert(['role_id' => $role_id, 'node_id' => $quan_id, 'pid' => 0, 'level' => 1]); } @($s_id = $_POST['s_id']); if (empty($s_id)) { if ($res) { echo "<script>alert('权限分配成功');location.href='index.php?r=role/role_list';</script>"; } else { echo "<script>alert('权限分配失败~~');location.href='index.php?r=role/add';</script>"; } } else { $que = new Query(); $que->select(['_id'])->from('role_node')->where(['node_id' => $s_id]); $arr = $que->one(); if ($arr) { echo "<script>alert('二级权限已存在,请从新添加~~');location.href='index.php?r=role/role_list';</script>"; } else { $data = $collection->insert(['role_id' => $role_id, 'node_id' => $s_id, 'pid' => $quan_id, 'level' => 2]); if ($data) { echo "<script>alert('权限分配成功');location.href='index.php?r=role/role_list';</script>"; } else { echo "<script>alert('权限分配失败~~');location.href='index.php?r=role/add';</script>"; } } } }
/** * Executes query and returns a single row of result. * @param Connection $db the Mongo connection used to execute the query. * If null, the Mongo connection returned by [[modelClass]] will be used. * @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]], * the query result may be either an array or an ActiveRecord object. Null will be returned * if the query results in nothing. */ public function one($db = null) { $row = parent::one($db); if ($row !== false) { if ($this->asArray) { $model = $row; } else { /* @var $class ActiveRecord */ $class = $this->modelClass; $model = $class::instantiate($row); $class::populateRecord($model, $row); } if (!empty($this->with)) { $models = [$model]; $this->findWith($this->with, $models); $model = $models[0]; } if (!$this->asArray) { $model->afterFind(); } return $model; } else { return null; } }
public function actionGetById() { $cookingtypeId = Yii::$app->request->get('cookingtypeId', ''); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if ($cookingtypeId != '') { $query = new Query(); $query->from('uhkklpCookingtype')->where(['_id' => $cookingtypeId]); $cookingType = $query->one(); return ['code' => 200, 'msg' => 'OK', 'result' => $this->formatCookingType($cookingType)]; } return ['code' => 1204, 'msg' => 'Type is not exist']; }
public function actionGetById() { $sampleId = Yii::$app->request->get('sampleId', ''); $query = new Query(); $query->from('uhkklpSample')->where(['_id' => $sampleId]); $sample = $query->one(); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['code' => 200, 'msg' => 'OK', 'result' => $sample]; }
public function actionSec_save() { $id = $_GET['id']; $query = new Query(); $query->select(['z_name', 'z_introduce', 'parent_id', 'z_content', 'practice_type'])->from('chapter_class')->where(["_id" => $id]); $rows = $query->one(); $que = new Query(); $que->select(['cha_name', 'lecturer'])->from('goods_class'); $data = $que->all(); return $this->renderPartial("sec_save", ['rows' => $rows, 'data' => $data]); }
public function actionJob_save() { $request = Yii::$app->request; $id = $request->get('id'); $query = new Query(); $query->select(['j_name', 'add_time'])->from('work_direction')->where(['_id' => $id]); $arr = $query->one(); //print_r($res);die; return $this->renderPartial('job_save', compact('arr')); }