I am working on a project in which to display some data i am using a custom query and saving those data in dataProvider. Passing that dataProvider to view file and displaying using a Listview
. just like below
<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>
I want to implement a search
bar for that Listview
. I am not using any SearchModel
so i am confused that how can i do that?
Here is my action
code.
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]);
}
I am just confused because i am not using any search model here so i dont know how can i search using title
of the event
.
In view you can use an active form for sending the value
<?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(); ?>
in your actionEvent you can
$this->layout = 'app';
if (isset($_GET('my_search')) {
// perform what you nedd ..
}
if(isset($_GET['latitude']) && isset($_GET['longitude'])){
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.