0
votes

in my index page I have this code to call search action:

$this->renderPartial('search');

and this is the search action code:

 $criteria = new CDbCriteria();

            if (isset($_GET['city'])) {
                $q = $_GET['city'];
                $criteria->compare('fileName', $q, true, 'OR');
                $criteria->compare('tags', $q, true, 'OR');
                $dataProvider = new CActiveDataProvider("Files", array('criteria' => $criteria));
                $this->redirect('result', array('dataProvider'=>$dataProvider));
            }

            $dataProvider = new CActiveDataProvider("Files", array('criteria' => $criteria));
            $this->render('search');

and this is the search view:

        <form method="get">
<?php
        $url = CHtml::normalizeUrl(array("files/search"));
        $model = Files::model();
        $c = new FilesController('view');
        $this->widget('zii.widgets.jui.CJuiAutoComplete',array(
            'model'=>$model,
            'id'=>'autocomplete',
            'attribute'=>$model->fileName,
            'name'=>'city',
            'source'=>$c->actionAutoComplete(),
            // additional javascript options for the autocomplete plugin
            'options'=>array(
                'minLength'=>'1',
            ),
            'htmlOptions'=>array(
                'style'=>'height:20px;',
                'placeholder'=>'search',
                'value'=>'isset($_GET["city"]) ? CHtml::encode($_GET["city"]) : "" ',
                ),)); 
?>
        <input type="submit" value="search" />


         </form>

I want to show the search results in another view, so once clicked the search submit button I want to redirect to another view to show the results, but in this code the search result is shown in the index page. so how to do it?

1

1 Answers

1
votes

you can either set the url that you want your form to be send, like:

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'action' => Yii::app()->createUrl('anotherController/anotherView'),
    'method' => 'post',
));

or you can redirect to another page after your done in index, like:

$this->redirect(array('anotherController/anotherView'));