Search in index page(how to show a blank page?)

Hi everyone…

I am working with the search engine in my index page.

My codes work will but I meet a problem.

I want the user to see NOTHING Before he/she clicks the search button.

Now, If the user don’t use the search button, my index page will list all stuff…(like a normal index)

I want the it to display nothing UNLESS the user search something…

Is that possible?

Thanks…

Hi

Make all thing under condition.

if(isset($_POST[‘search’])){

// Your Sql query and code

}

Thanks

Thanks for your help…

But I tried your code … it always gives me the blank php page…

Here is my code… Where exactly should I put your code…? Thanks so much!


public function actionIndex()

{


    $model=new University('search');

    $model->unsetAttributes();  // clear any default values

    if(isset($_GET['University']))

        $model->attributes=$_GET['University'];

 

    //send model object for search

    $this->render('index',array(

        'dataProvider'=>$model->search(),

        'model'=>$model

)); 

}

Hi

You have to use

public function actionIndex()

{

$model=new University('search');


$model->unsetAttributes();  // clear any default values


if(isset($_GET['University'])){


    $model->attributes=$_GET['University'];





//send model object for search


$this->render('index',array(


    'dataProvider'=>$model->search(),


    'model'=>$model


));

}else{

$this->render(‘index1’)); // Make this temp index

}

}

This code… instead… will give me a view about index1.

But without search button etc.

Do I need to make another revision of index page?

Any simpler way to do this…? I just need a blank view if you don’t click search.

Here is my view…


//search

Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

    $('.search-form').toggle();

    return false;

});

$('.search-form form').submit(function(){

    $.fn.yiiListView.update('universitylistview', { 

        //this entire js section is taken from admin.php. w/only this line diff

        data: $(this).serialize()

    });

    return false;

});

");

?>


<h1>Universities</h1>

<div><br>

<?php echo CHtml::link('Search University','#',array('class'=>'search-button btn btn-primary','data-title'=>'Search', 'data-content'=>'You can search your university either by its full name or partial name.', 'rel'=>'popover')); ?>

<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'=>'universitylistview',

        

)); ?>



Thanks so much for your help!!!

Hi

Than do like below

Controller file code

public function actionIndex()

{

&#036;model=new University('search');


&#036;model-&gt;unsetAttributes();  // clear any default values


&#036;show_cont = 0;


if(isset(&#036;_GET['University'])){


    &#036;model-&gt;attributes=&#036;_GET['University'];


    &#036;show_cont = 1;


}





//send model object for search


&#036;this-&gt;render('index',array(


    'dataProvider'=&gt;&#036;model-&gt;search(),


    'model'=&gt;&#036;model,


    'show_cont' =&gt; &#036;show_cont,

));

}

View File Code

//search

Yii::app()->clientScript->registerScript(‘search’, "

$(’.search-button’).click(function(){

&#036;('.search-form').toggle();


return false;

});

$(’.search-form form’).submit(function(){

&#036;.fn.yiiListView.update('universitylistview', { 


    //this entire js section is taken from admin.php. w/only this line diff


    data: &#036;(this).serialize()


});


return false;

});

");

?>

<h1>Universities</h1>

<div><br>

<?php echo CHtml::link(‘Search University’,’#’,array(‘class’=>‘search-button btn btn-primary’,‘data-title’=>‘Search’, ‘data-content’=>‘You can search your university either by its full name or partial name.’, ‘rel’=>‘popover’)); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial(’_search’,array(

'model'=&gt;&#036;model,

)); ?>

</div>

<?php if($show_cont == 1){ $this->widget(‘zii.widgets.CListView’, array(

    'dataProvider'=&gt;&#036;dataProvider,


    'itemView'=&gt;'_view',


    'id'=&gt;'universitylistview',

)); } ?>

In this case whenever you will search than show a list otherwise only Search area show you.

Thanks

That works perfectly…

Thanks so much!!!!

But still…this code throws me another simple question…

If I leave the search box blank and click search…

I still got all stuff…(which I don’t want the user see)

Should I write something in my model?


public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

                $criteria->compare('name',strtoupper($this->name),true);    //this will ensure I can search some similar result.

     //$criteria->compare('name',$this->name);

     // $criteria->compare('name','>='.$this->name); 


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

Hi

Than do like below

Controller file code

public function actionIndex()

{

$model=new University(‘search’);

$model->unsetAttributes(); // clear any default values

$show_cont = 0;

if(isset($_GET[‘University’]) && $_GET[‘University’] != ‘’){

$model->attributes=$_GET[‘University’];

$show_cont = 1;

}

//send model object for search

$this->render(‘index’,array(

‘dataProvider’=>$model->search(),

‘model’=>$model,

‘show_cont’ => $show_cont,

));

}

Thanks