how to put a search engine/search site on your webapp?

i actually had a _search.php in the views of my model containing this.


<div class="wide form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'post',

)); ?>


	<div class="row">

		<?php echo $form->label($model,'id'); ?>

		<?php echo $form->textField($model,'id'); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'title'); ?>

		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'sport_name'); ?>

		<?php echo $form->textField($model,'sport_name',array('size'=>40,'maxlength'=>40)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'subheader'); ?>

		<?php echo $form->textField($model,'subheader',array('size'=>60,'maxlength'=>255)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'description'); ?>

		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'streamurl'); ?>

		<?php echo $form->textField($model,'streamurl',array('size'=>60,'maxlength'=>255)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'price'); ?>

		<?php echo $form->textField($model,'price'); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'thumbnail'); ?>

		<?php echo $form->textField($model,'thumbnail',array('size'=>60,'maxlength'=>255)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'promoimage'); ?>

		<?php echo $form->textField($model,'promoimage',array('size'=>60,'maxlength'=>255)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'airdate'); ?>

		<?php echo $form->textField($model,'airdate'); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'publish'); ?>

		<?php echo $form->textField($model,'publish'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Search'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- search-form -->

but this is only in the admin section…

the frontend doesnt have a search section… i guess the client generated the model using previous versions of yii framework…

anyway… i’m finding a way to just put or code things up so a search section will be on the frontend… just to search the whole site… any help is greatly appreciated… thanks. ;)

bump

What do you mean with "searching the whole site"?

Searching in all tables of the database?

hmmm… nope… just the little ones… like specific lists on your model… pretty much like the search section on a wordpress site, only that it doesn’t search for posts. :)

I still don’t understand what you have to do… Can you provide some more concrete examples, like how it should work?

hmm… for example i have a model named Events as a primary model and if the user wants to search a specific event or just about anything he would enter something on a search field above and hit the search button and voila… just like on a wordpress search.php/searchform.php

You can create a form with just one field and then use this for search in all field of the model.

You can edit search in the model like that:




public function search()

{

   $criteria=new CDbCriteria;


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

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

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

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

   [...]

}



Like that the data collected in name (or anyone else field, doesn’t matter) will be used for search in all field.

The third parameter says to use OR for joining the conditions.

Is that what you mean?

yep pretty much like that… like searching for just about anything. i think i hafta search inside the database… not in the page.

still need help, a more illustrative example would do… thanks


public function search()

{

   $criteria=new CDbCriteria;


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

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

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

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

   $find = ModelName::model()->findAll($criteria);


$this->render('_search', array('results'=>$find));

}

does that help

can i do this for a widget? and for the search result to be displayed in $content.

Look at the implementation used in the admin views that the crud generator creates. It should be pretty clearly evident there.

~thinkt4nk