Php 无法使用yii框架编辑特定用户数据

Php 无法使用yii框架编辑特定用户数据,php,yii,Php,Yii,我是yii框架的新手。我正在使用yii框架进行更新操作。我有一个名为sitecontroller.php、model jobseekerprofile.php、view personal.php的控制器。我的表格是求职者档案,包含id、用户id、联系人编号、性别、dob、mstatus、地址等字段。我无法通过表单发布更新数据 我的控制器是sitecontroller.php class SiteController extends Controller { public function

我是yii框架的新手。我正在使用yii框架进行更新操作。我有一个名为sitecontroller.php、model jobseekerprofile.php、view personal.php的控制器。我的表格是求职者档案,包含id、用户id、联系人编号、性别、dob、mstatus、地址等字段。我无法通过表单发布更新数据

我的控制器是sitecontroller.php

class SiteController extends Controller
{
    public function actionpersonal()
    {
        $user_id = trim($_GET['id']);
        $model = new jobseekerprofile();
        $model = jobseekerprofile::model()->find(array(
            'select' => 'contact_no,address', "condition" => "user_id=$user_id",
            'limit' => 1,));
        $model = $this->loadModel($user_id);
        if (isset($_POST['jobseekerprofile'])) {
            $model->attributes = $_POST['jobseekerprofile'];
            if ($model->save()) {
                $this->redirect(array('profile', 'user_id' => $model->user_id));
            }
        }
        $this->render('personal', array('model' => $model));
    }

    public function loadModel($user_id)
    {
        echo $model = jobseekerprofile::model()->findByPk($user_id);
        if ($model === null)
            throw new CHttpException(404, 'The requested page does not exist.');
        return $model;
    }
}
    <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";
}
?>
    <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">

        <?php echo $form->labelEx($model, 'Address'); ?>
        <?php echo $form->textField($model, 'address'); ?>
        <?php echo $form->error($model, 'address'); ?>
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton('Save'); ?>
    </div>


<?php $this->endWidget(); ?>
 rules in model


public function rules()
  {
    return array(
                array('contact_no,gender,dob,address,mstatus','required'),
    );
 }
查看personal.php

class SiteController extends Controller
{
    public function actionpersonal()
    {
        $user_id = trim($_GET['id']);
        $model = new jobseekerprofile();
        $model = jobseekerprofile::model()->find(array(
            'select' => 'contact_no,address', "condition" => "user_id=$user_id",
            'limit' => 1,));
        $model = $this->loadModel($user_id);
        if (isset($_POST['jobseekerprofile'])) {
            $model->attributes = $_POST['jobseekerprofile'];
            if ($model->save()) {
                $this->redirect(array('profile', 'user_id' => $model->user_id));
            }
        }
        $this->render('personal', array('model' => $model));
    }

    public function loadModel($user_id)
    {
        echo $model = jobseekerprofile::model()->findByPk($user_id);
        if ($model === null)
            throw new CHttpException(404, 'The requested page does not exist.');
        return $model;
    }
}
    <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";
}
?>
    <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">

        <?php echo $form->labelEx($model, 'Address'); ?>
        <?php echo $form->textField($model, 'address'); ?>
        <?php echo $form->error($model, 'address'); ?>
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton('Save'); ?>
    </div>


<?php $this->endWidget(); ?>
 rules in model


public function rules()
  {
    return array(
                array('contact_no,gender,dob,address,mstatus','required'),
    );
 }

有人帮我吗?

你需要用大写字母

Jobseekerprofile.php和
$model=new Jobseekerprofile()至少,我甚至可以称之为:JobseekerProfile.php和
$model=newjobseekerprofile()或者什么的

示例控制器(未测试):

您还可以将用于这些标准表单的。它将根据您的数据库及其关系生成表单