我是yii框架的新手。我在yii框架中进行更新操作。我的控制器名称为sitecontroller.php,model jobseekerprofile.php,view personal.php。首先,我想选择数据并在文本框中以表格形式显示。我收到了一条错误消息'数组到字符串转换'。
我的控制器页面sitecontroller.php
<?php
class SiteController extends Controller
{
public function actionpersonal()
{
$user_id = trim($_GET['id']);
$model=jobseekerprofile::model()->findAll(array(
'select'=>'contact_no',"condition"=>"user_id=$user_id",
'limit'=>3,));
$this->render('personal',array('model' =>$model));
}
}
?>
模型 - jobseekerprofile.php
<?php
class Jobseekerprofile extends CActiveRecord
{
public $contact_no;
public $dob;
public $gender;
public $mstatus;
public $address;
public $user_id;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'job_seeker_profile';
}
public function rules()
{
return array(
array('email,contact_no,gender,dob,address,mstatus','required'),
);
}
/*public function rules()
{
return array(
// All Fields Required //
array('name,email,password,contact_no,gender,mstatus','required'),
array('name,email,password','required'),
array('email','email'),
array('email', 'unique','message'=>'Email already exists!'),
array('contact_no', 'numerical', 'integerOnly'=>true),
);
}*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
public function attributeLabels()
{
return array(
'user_id' => 'User_ID',
'contact_no' => 'Contact_no',
'gender' => 'Gender',
'dob' => 'Dob',
'mstatus' => 'Mstatus',
'address' => 'Address',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('contact_no',$this->contact_no,true);
$criteria->compare('gender',$this->gender,true);
$criteria->compare('dob',$this->dob,true);
$criteria->compare('mstatus',$this->mstatus,true);
$criteria->compare('address',$this->address,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
?>
查看-personal.php
<div>
<?php
require_once('profile_menu.php');
?>
<div style="float:right;margin-right:285px;">
<h1>Update Personal Detail</h1>
<?php
foreach($model as $models)
{
echo $models->contact_no."</br>";
}
?>
<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->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>
</div>
有人帮帮我吗?