1 HTML: 2 3 <div> 4 <form class="form-inline " method="get" action="<?=Url::to(['companylist']);?>"> 5 <div class="form-group"> 6 <input type="text" name="name" style=" 80%; display:inline;" class="form-control input-sm" placeholder="配电室编号 或 配电室名称" value="<?=$_GET['name'];?>"> 7 <button type="submit" style="float: right" class="btn btn-primary btn-sm">查询</button> 8 </div> 9 </form> 10 </div> 11 控制器的查询条件: 12 $data = Concentrator::find()->andWhere(['in', 'id', $cIds]); 13 if ($_GET['name']) { 14 $data->andWhere(['or', ['like', 'number', $_GET['name']], ['like', 'name', $_GET['name']]]); 15 } 16 //in 17 $data->andWhere(['in', 'state', [1, 2, 3]]); 18 //between 19 $data->andFilterWhere(['between', 'create_time', $start_date, $end_date]); 20 $rowset = $data->all(); 21 echo $data->createCommand()->getRawSql(); //输出sql语句
1 ['and', 'id=1', 'id=2'] //id=1 AND id=2 2 3 ['and', 'type=1', ['or', 'id=1', 'id=2']] //type=1 AND (id=1 OR id=2) 4 5 ['between', 'id', 1, 10] //id BETWEEN 1 AND 10 6 7 ['not between', 'id', 1, 10] //not id BETWEEN 1 AND 10 8 9 ['in', 'id', [1, 2, 3]] //id IN (1, 2, 3) 10 11 ['not in', 'id', [1, 2, 3]] //not id IN (1, 2, 3) 12 13 ['like', 'name', 'tester'] //name LIKE '%tester%' 14 15 ['like', 'name', ['test', 'sample']] //name LIKE '%test%' AND name LIKE '%sample%' 16 17 ['not like', 'name', ['or', 'test', 'sample']] //not name LIKE '%test%' OR not name LIKE '%sample%' 18 19 ['like', 'name', '%tester', false] // name LIKE '%tester' 20 21 ['exists','id', $userQuery] //EXISTS (sub-query) | not exists 22 23 ['>', 'age', 10] //age>10 24 where(['<>','id',10]) //不等于
session: $session = Yii::$app->session; $session['user'] = [ 'id' => 1, 'username' => 'yiiuser', ]; echo $session['user']['id']; echo $session['user']['username'];