我是yii框架的新手。我在yii框架中进行更新操作。我的控制器名称为 sitecontroller.php ,模型 jobseekerprofile.php ,查看 personal.php 。首先,我想选择数据并在文本框中以表格形式显示。我收到了一条错误消息
Array to string conversion.
我的控制器页面 sitecontroller.php :
<?php
class SiteController extends Controller
{
public function actionpersonal()
{
$user_id = trim($_GET['id']);
/*$criteria = new CDbCriteria();
$criteria->compare('user_id', '97');
$model = jobseekerprofile::model()->findAll($criteria);*/
var_dump($user_id);
$model=jobseekerprofile::model()->findAll(array(
'select'=>'contact_no',"condition"=>"user_id=$user_id",
'limit'=>1,));
$this->render('personal',array('model' =>$model));
}
}
?>
查看 - personal.php :
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'clientOptions'=>array(
'validateOnSubmit'=>true
),
)); ?>
<?php
foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
}
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<?php //echo $form->textField($model,'pp_status', array('value'=>'Open', 'readonly' => 'true')); ?>
<?php echo $form->labelEx($model,'Contact No'); ?>
<?php echo $form->textField($model,'contact_no'); ?>
<?php echo $form->error($model,'contact_no'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
有人帮帮我吗?
答案 0 :(得分:1)
方法findAll()
返回模型数组,以获得一个应使用find()
方法的模型
$model=jobseekerprofile::model()->find(array(
'select'=>'contact_no',
"condition"=>"user_id=$user_id",
));