Php 使用yii框架搜索和显示记录时出错

Php 使用yii框架搜索和显示记录时出错,php,yii,Php,Yii,我是yii框架的新手。我正在数据库中进行搜索记录,并使用yii框架在另一个页面中显示。我的控制器是Sitecontroller.php,查看页面是search.php和search_result.php。我的模型是job.php urlencode()要求参数1为字符串,对象为给定值 C:\wamp\www\yii\framework\web\CUrlManager.php(440)” 我的控制器是Sitecontroler.php <?php class SiteController e

我是yii框架的新手。我正在数据库中进行搜索记录,并使用yii框架在另一个页面中显示。我的控制器是Sitecontroller.php,查看页面是search.php和search_result.php。我的模型是job.php urlencode()要求参数1为字符串,对象为给定值

C:\wamp\www\yii\framework\web\CUrlManager.php(440)”

我的控制器是Sitecontroler.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'];
        $title=trim($title);
        $model=Job::model()->find(array('select'=>'*',"condition"=>"title like '%$title%'",));
        $number=count($model);
        if($number>0)
        {
          $this->redirect($this->createUrl('site/search_result',array('title'=>$title)));       
        }

      }
   $this->render('search',array('model' =>$model));
 }
public function actionsearch_result()
  {
    $title=$_GET['title'];  
    $model = new Job ;
    $model=Job::model()->find(array('select'=>'*',"condition"=>"title like '%$title%'",));
    $this->render('search_result',array('model' =>$model));
 }  
 }?>

我认为问题可能是,你的行为命名不正确。
您应该使用
camelCase

public function actionSearch()
...
public function actionSearch_result()
这是Yii需要的命名,因此它可以找到您的操作。
redirect
方法需要一个操作,如果没有这个,我想它找不到它

此外,重定向需要一个
controller/action
路由,这意味着在您的情况下,它应该是:

$this->redirect(array('site/search_result','model' =>$model)); 

请记住,该函数是actionSearch_结果,大写字母为S,但路由本身是
site/search_结果
,小写字母为S

,这一行存在问题

$this->redirect(array('site/Search_result',array('model' =>$model))); 
$model=Job::model()->find(array('select'=>'*',"condition"=>"title like '%$title%'",));
你应该试试这个

$this->redirect($this->createUrl('site/search_result',array('parameter'=>'value'))); 
注意:-您不能通过URL发送$model,因为它是一个对象,这就是为什么会出现此错误。

更新

在您的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>
更改此代码

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
}
如您所见,您已使用find()获取数据。因此find()将返回一行(因此是一个对象),而不是一个对象数组。如果要获取多条记录,则应使用findAll()

因此,当使用findAll()时,代码变得

$model=Job::model()->findAll(array('select'=>'*',"condition"=>"title like '%$title%'",));
然后,您可以使用与在search_result.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
}
foreach($model作为$models)
{ 
?>

请查看我的控制器代码,我已对其进行了更改。再次显示这些相同的错误。您的错误仍然存在,请查看我的更新-您应该只重命名函数名称。。此外,
model->$model
不应位于单独的数组中。请检查文档。操作中是否有下划线并不重要名称或有小写字母“s”。我已经更改了控制器代码。请查看它。现在显示了试图获取非对象C:\wamp\www\yii\jobsite\u original\protected\views\site\search\u result.php的属性时出现的错误。您能告诉我哪一行是第26行吗?在search\u result.php中,这样我只得到了一行,但我想要该表中的所有行
$model=Job::model()->findAll(array('select'=>'*',"condition"=>"title like '%$title%'",));
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
}