【发布时间】:2014-04-04 09:27:50
【问题描述】:
我是 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));
}
}?>
我的查看文件-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>
有没有人帮帮我?
【问题讨论】: