select() public method

Sets the list of fields of the results to return.
public select ( array $fields )
$fields array fields of the results to return.
Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public function actionIndex()
 {
     $query = new Query();
     $query->select(["username", "password"])->from("admin_user");
     $re = $query->all();
     //print_r($re);die;
     return $this->renderPartial('index', ["data" => $re]);
 }
Exemplo n.º 3
0
 static function GetForms()
 {
     $query = new Query();
     // compose the query
     $query->select([])->from('forms');
     // execute the query
     $rows = $query->all();
     return $rows;
 }
 /**
  * @inheritdoc
  */
 protected function findTemplate($name)
 {
     $query = new Query();
     $template = $query->select($this->templateDataFields)->from($this->templateCollection)->where([$this->templateNameField => $name])->one();
     if ($template === false) {
         return null;
     }
     return $template;
 }
Exemplo n.º 5
0
 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>";
     }
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function getHistory($chatId, $limit = 10)
 {
     $query = new Query();
     $query->select(['user_id', 'username', 'message', 'timestamp', 'avatar_16', 'avatar_32'])->from(self::collectionName())->where(['chat_id' => $chatId]);
     $query->orderBy(['timestamp' => SORT_DESC]);
     if ($limit) {
         $query->limit($limit);
     }
     return $query->all();
 }
Exemplo n.º 7
0
 /**
  * Retrieves a value from cache with a specified key.
  * This method should be implemented by child classes to retrieve the data
  * from specific cache storage.
  * @param string $key a unique key identifying the cached value
  * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
  */
 protected function getValue($key)
 {
     $query = new Query();
     $row = $query->select(['data'])->from($this->cacheCollection)->where(['id' => $key, '$or' => [['expire' => 0], ['expire' => ['$gt' => time()]]]])->one($this->db);
     if (empty($row)) {
         return false;
     } else {
         return $row['data'];
     }
 }
Exemplo n.º 8
0
 public function testSelect()
 {
     // default
     $query = new Query();
     $select = [];
     $query->select($select);
     $this->assertEquals($select, $query->select);
     $query = new Query();
     $select = ['name', 'something'];
     $query->select($select);
     $this->assertEquals($select, $query->select);
 }
 public static function findAll(array $attributes = [])
 {
     $query = new Query();
     $class_name = get_called_class();
     $instance = new $class_name();
     $table_name = $instance->getTableName();
     $results = $query->select($instance->getAttributesArray())->from($table_name)->where($attributes)->all();
     $objs = [];
     foreach ($results as $key => $result) {
         $objs[$key] = new $class_name();
         $objs[$key]->setAttributes($result);
     }
     return $objs;
 }
Exemplo n.º 10
0
 public function actionCheck_login()
 {
     //print_r($_POST);
     $username = $_POST['username'];
     $arr = array('username' => $username);
     $query = new Query();
     $query->select(['username', 'password'])->from('admin_user')->where($arr);
     $rows = $query->all();
     //echo $rows[0]['password'];die;
     if ($rows) {
         if ($rows[0]['password'] == md5($_POST['password'])) {
             $_SESSION['user_info'] = $username;
             echo $this->success("登陆成功", "index.php?r=index/index", '1');
         } else {
             echo $this->error("密码错误,登陆失败", "index.php?r=public/login", '1');
         }
     } else {
         echo $this->error("账号错误,登陆失败", "index.php?r=public/login", '1');
     }
 }
Exemplo n.º 11
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $dsn = "mongodb://192.168.1.164";
     $connection = new \yii\mongodb\Connection(['dsn' => $dsn]);
     $connection->open();
     //var_dump($connection);die;
     $database = $connection->getDatabase('niuke');
     /*
     		$collection = $database->getCollection('user');
     		//var_dump($collection);die;	
     */
     $query = new Query();
     // compose the query
     $query->select(['niukename', 'password'])->from('user')->limit(10);
     // execute the query
     $rows = $query->all();
     var_dump($rows);
     /*
             //return $this->render('index');*/
 }
Exemplo n.º 12
0
 /**
  * Ensures migration history contains at least base migration entry.
  */
 protected function ensureBaseMigrationHistory()
 {
     if (!$this->baseMigrationEnsured) {
         $query = new Query();
         $row = $query->select(['version'])->from($this->migrationCollection)->andWhere(['version' => self::BASE_MIGRATION])->limit(1)->one($this->db);
         if (empty($row)) {
             $this->addMigrationHistory(self::BASE_MIGRATION);
         }
         $this->baseMigrationEnsured = true;
     }
 }
Exemplo n.º 13
0
 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>";
             }
         }
     }
 }
Exemplo n.º 14
0
 /**
  * @param $queryParam
  * @return array
  */
 public static function itemsList($queryParam)
 {
     if (is_numeric($queryParam)) {
         $query = new Query();
         $query->select(['_id' => false, 'number' => 'text'])->from(Number::collectionName())->where(['like', 'number', $queryParam]);
     } else {
         $query = new \yii\db\Query();
         $query->select(["CONCAT_WS(' ',last_name, first_name, middle_name) AS number"])->from(Employee::tableName())->where(['like', 'last_name', $queryParam]);
     }
     $items['results'] = array_map(function ($item) {
         $item['id'] = $item['number'];
         return $item;
     }, $query->limit(10)->all());
     return $items;
 }
Exemplo n.º 15
0
 public function actionFen_role()
 {
     $user = $_GET['id'];
     $query = new Query();
     $query->select(['r_name'])->from('role')->where(['r_status' => 1, 'r_status' => '1']);
     $rows = $query->all();
     return $this->renderPartial('fen_role', ['user' => $user, 'rows' => $rows]);
 }
Exemplo n.º 16
0
 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]);
 }
Exemplo n.º 17
0
 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'));
 }
Exemplo n.º 18
0
 public function actionHuan()
 {
     $id = $_GET['id'];
     if ($id == 1) {
         return 0;
         exit;
         //不查数据
     }
     $dd = $id - 1;
     $query = new Query();
     $query->select(['nickname'])->from('node')->where(['n_level' => "{$dd}"]);
     $rows = $query->all();
     //var_dump($rows);
     echo json_encode($rows);
 }