我是yii框架中的新手。我正在做數據庫中的搜索數據。 但我得到了錯誤使用yii框架進行搜索操作的錯誤
錯誤
Unable to resolve the request "jobsite/error". (C:\wamp\www\yii\framework\web\CWebApplication.php:286).
我controller
是Sitecontroller.php
,model
爲job
,我VIE頁面seach.php
和search_result.php
。我table
名字是jobs
。 //我的代碼如下。 //控制器是Sitecontroller.php
<?php
class SiteController extends Controller
{
public function actionsearch()
{
$user_id = trim($_GET['id']);
$model = new Job ;
if(isset($_POST['Job']))
{
$model->attributes=$_POST['Job'];
$title=$_POST['Job']['title'];
$model=Job::model()->find(array('select'=>'*',"condition"=>"title like '%$title%'",));
$number=count($model);
if($number>0)
{
$this->redirect(array('site/search_result','model'=>$model));
}
}
$this->render('search',array('model' =>$model));
}
public function actionsearch_result()
{
$model = new Job ;
$this->render('search_result',array('model' =>$model));
}
}
?>
//model-job.php
規則部分
<?php
public function rules()
{
return array(
array('title,key_skills','required'),
);
}
?>
//view-search.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>false,
'htmlOptions' => array(),
'clientOptions'=>array(
'validateOnSubmit'=>true
),
)); ?>
<?php
foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
}
?>
<div class="row">
<?php echo $form->labelEx($model,'Keyword'); ?>
<?php echo $form->textField($model,'title'); ?>
<?php echo $form->error($model,'title'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
//view-search_result.php
<div style="float:right;margin-right:285px;">
<h1>Search Jobs</h1>
<table width="200" border="1">
<tr>
<td>SI No</td>
<td>Title</td>
<td>Key Skill</td>
<td>Experince</td>
</tr>
<?php
foreach($model as $models)
{
?>
<tr>
<td></td>
<td><?php echo $models->title; ?></td>
<td><?php echo $models->key_skills; ?></td
><td><?php echo $models->experience; ?></td
></tr>
<?php
}
?>
</table>
</div>
有人幫我嗎?
你的錯誤頁面在哪裏?我認爲頁面工地/錯誤不存在。 – Dinistro
search_result.php是我的錯誤頁面。 – user3475251
女巫是你的錯誤行爲?注意:如果您有y語法錯誤,則會調用錯誤操作。這個動作在主配置 – Dinistro