我正在开发一个项目,在其中显示一些数据,我正在使用自定义查询并将这些数据保存在dataProvider中。传递dataProvider以查看文件并使用$sql = "UPDATE user SET `niveua`='beginner' WHERE `km`< 50";
$result = $con->query($sql);
$sql = "UPDATE user SET `niveua`='trained' WHERE `km`> 50 or `km` < 99";
$result = $con->query($sql);
$sql = "UPDATE user SET `niveua`='expert' WHERE `km`> 100";
$result = $con->query($sql);
进行显示。就像下面一样
Listview
我想为<nav class="navbar navbar-fixed-top">
<form class="navbar-form navbar-left search-form" action="">
<div class="form-group"><input type="text" class="form-control app-search" placeholder="Search">
</div>
</form>
</nav>
<div class="panel-group" id="accordion">
<?= \yii\widgets\ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'eventlistview',
'layout' => "{items}",
]); ?>
</div>
实现search
栏。我没有使用任何Listview
,所以我很困惑,我怎么能这样做?
这是我的SearchModel
代码。
action
我很困惑,因为我在这里没有使用任何搜索模型,因此我不知道如何使用public function actionEvent()
{
$this->layout = 'app';
if(isset($_GET['latitude']) && isset($_GET['longitude'])){
$query = new Query();
$query ->select(['e.*','COUNT(d.event_id) as checkins' ,'o.clubname',new Expression("case when c.id is not null then 1 else 0 end is_checkedin")])
->from('event e')
->innerJoin('organiser o', 'e.organiser_id = o.organiser_id')
->leftJoin('checkin c', 'c.event_id = e.id and c.user_id ='.$_GET['user_id'])
->leftJoin('checkin d', 'd.event_id = e.id' )
->where('e.interest_id IN
( SELECT area_intrest.id FROM area_intrest, user WHERE FIND_IN_SET(area_intrest.id,user.area_intrest) AND user.id='.$_GET['user_id'].')')
->groupBy('e.id');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
}
return $this->render('event' ,['dataProvider' => $dataProvider]);
}
的{{1}}进行搜索。
答案 0 :(得分:1)
在视图中,您可以使用活动表单发送值
<?php
$form = ActiveForm::begin(['id' => 'my-form',
'method'=>'get',
'action' => Url::to('your-controller/event')]);
?>
<input type="text" class="form-control app-search" name="my_search" placeholder="Search">
<?= Html::submitButton('search') ?>
<?php ActiveForm::end(); ?>
在你的actionEvent中你可以
$this->layout = 'app';
if (isset($_GET('my_search')) {
// perform what you nedd ..
}
if(isset($_GET['latitude']) && isset($_GET['longitude'])){