简体   繁体   中英

Error in search operation using yii framework

I am new in yii framework.I am doing search data in database. But i got the error

error

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

My controller is Sitecontroller.php , model is job ,my vie pages are seach.php and search_result.php .My table name is jobs . //My codes are given below. //Controller is 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

rules section

 <?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>

Anybody help me?

You had the wrong error page setted in the main-config. (protected/config/main.php)

you should set an error action to the error handler (or reset it to a valid page).

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

In the error.php (View) you need to have <?php echo CHtml::encode($message); ?> <?php echo CHtml::encode($message); ?> that the errrors will be printed.

Here you can find an explanation of the Yii error handling

If you had implemented this, Yii will be able to show you the error resulting from the sql query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM