我是yii框架中的新功能。我正在做數據庫中的重新搜索並使用yii框架在另一個頁面中顯示。我的控制器是Sitecontroller.php,查看頁面是search.php和search_result .PHP。我的模型是job.php.My錯誤是 「urlencode()期望參數1是字符串,對象給出使用yii框架在搜索和顯示記錄中的錯誤
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));
}
}?>
我的視圖文件,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>
視圖文件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>
任何機構幫助我嗎?
我已經改變了控制器的代碼。請看看它。現在顯示錯誤嘗試獲取非物體的屬性 C:\ wamp \ www \ yii \ jobsite_orginal \ protected \ views \ site \ search_result.php(26) – user3475251
你能告訴哪一行是第26行嗎? –
<?php echo $ models-> title; ?>在search_result.php – user3475251