2014-04-04 31 views
1

我是yii框架中的新手。我正在做數據庫中的搜索數據。 但我得到了錯誤使用yii框架進行搜索操作的錯誤

錯誤

Unable to resolve the request "jobsite/error". (C:\wamp\www\yii\framework\web\CWebApplication.php:286). 

controllerSitecontroller.phpmodeljob,我VIE頁面seach.phpsearch_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> 

有人幫我嗎?

+0

你的錯誤頁面在哪裏?我認爲頁面工地/錯誤不存在。 – Dinistro

+0

search_result.php是我的錯誤頁面。 – user3475251

+0

女巫是你的錯誤行爲?注意:如果您有y語法錯誤,則會調用錯誤操作。這個動作在主配置 – Dinistro

回答

0

您在主配置中設置了錯誤的錯誤頁面。 (protected/config/main.php)

您應該爲錯誤處理程序設置錯誤操作(或將其重置爲有效頁面)。

'errorHandler'=>array(
    'errorAction'=>'site/error', 
), 

在error.php(查看),你需要有<?php echo CHtml::encode($message); ?>該errrors將被打印出來。

在這裏你可以找到,如果你已經實現了這個的Yii error handling

的解釋,Yii的將能夠向你展示從SQL查詢得到的錯誤。

+0

編輯控制器頁面 – user3475251

+0

新錯誤是urlencode()期望參數1爲字符串,給定對象C:\ wamp \ www \ yii \ framework \ web \ CUrlManager.php(440) – user3475251

+0

我已經添加了上面的頁面。 – user3475251