This is what I did. Its the EASIEST solution that I know of. I just reused the advanced search done in CGridView.
In my controller file
public function actionIndex()
{
$model=new Blogs('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Blogs']))
$model->attributes=$_GET['Blogs'];
//send model object for search
$this->render('index',array(
'dataProvider'=>$model->search(),
'model'=>$model)
);
}
In my view file (namely my index file)
<?php
$this->breadcrumbs=array(
'Blogs',
);
$this->menu=array(
array('label'=>'Create Blogs', 'url'=>array('create')),
array('label'=>'Search Blogs', 'url'=>array('admin')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiListView.update('blogslistview', {
//this entire js section is taken from admin.php. w/only this line diff
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Blogs</h1>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'id'=>'blogslistview', // must have id corresponding to js above
'sortableAttributes'=>array(
'id',
'startdate',
'enddate',
'user_id',
),
));
?>
Bookmarked!
Thank you!
Good tutorial
Served my requirement.
Nice tutorial, thank you
niceeeeee
Works great!
Thank you very much. I am using this and it does work.
Really Works
This one works after trying other solutions.
Nice tutorial
Thank you!
I have some other requirements , I want to add a filter to the search result which is shown in the list view after searching, Like grid view search.
Thank you in advance
Thanks for this
You just saved me some hours. Thank you
Awesome!
Just tried it out on a list view and worked like a charm :D.
I was forgetting to use yiiListView instead of yiiGridView on the javascript. Saved me hours of headaches for such an obvious mistake.
Thank you!!
the right wiki at the right time
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.