0
我正在嘗試在我的項目中實現搜索操作,即job portal。我試圖在同一頁上顯示結果,不知道該怎麼做。我做了以下事情。yii中的搜索操作
控制器
$model = new SearchEmployee();
/*Getting Data From Search Form For Processing */
if (isset($_POST['SearchEmployee'])) {
$model->attributes = $_POST['SearchEmployee'];
$category = $_POST['SearchEmployee']['category_id'];
$skills = $_POST['SearchEmployee']['skills'];
$experience = $_POST['SearchEmployee']['experience'];
$model = SearchEmployee::model()->find(array(
'select' => array('*'), "condition" => "category_id=$category AND key_skills like'%$skills%'AND experience=$experience",
));
if($model==null)
{
Yii::app()->user->setFlash('success', "No Results");
$this->render('search');
}
else
{
$this->render('search', array('model' => $model));
}
}
/*Getting Data From Search Form For Processing */
$this->render('search', array('model' => $model));
查看:一個簡短的代碼
<?php
/* @var $this SiteController */
/* @var $model LoginForm */
/* @var $form CActiveForm */
$this->pageTitle=Yii::app()->name . ' - Search Employee';
$this->breadcrumbs=array(
'Search Employee',
);
$list = CHtml::listData(Category::model()->findAll(),'id','title');
?>
<h1>Search Employees</h1>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
//Search Form//
<div class="row">
<?php echo $form->labelEx($model,'Skills'); ?>
<?php echo $form->textField($model,'skills'); ?>
<?php echo $form->error($model,'skills'); ?>
</div>
//Search Form// //Result Display//
<div class="view">
<h1>Results</h1>
<div class="view" id="id">
<h1>Records Display</h1>
<h4>
Name:
<?php echo $form->labelEx($model,'skills Required'); ?>
</h4>
<h4>
Skills:
<?php echo $form->labelEx($model,'Skills Required'); ?>
</h4>
<h4>
Experience:
<?php echo $form->labelEx($model,'Skills Required'); ?>
</h4>
<h5>
<?php echo CHtml::submitButton('VIew Details'); ?>
</h5>
</div>
</div>
它工作到模型代碼被執行,但同時redirectig回到頁面顯示的錯誤。 '模型未定義'。
Asped ......我懷念那個代碼,同時發佈...已編輯question..have一個look.And你建議在查詢之後包含搜索,對吧。? – saji