Yii与CActiveForm的表单子模块


Yii form submition with CActiveForm

我只需要做一个注册表,我正在努力用CActiveForm完成这项任务。基本上它只是在表单提交中插入一个新的数据库记录。这就是我的,

MyView

<!--begin a form-->
<?php $form = $this->beginWidget('CActiveForm', array(
   'id'=>'user-registration-form',
   'enableAjaxValidation'=>true,
   'enableClientValidation'=>true,
   'focus'=>array($model,'firstName'),
)); ?>
<!--error handling-->
<?php echo $form->errorSummary($model); ?>
<div class="row">
   <?php echo $form->labelEx($model,'firstName'); ?>
   <?php echo $form->textField($model,'firstName'); ?>
   <?php echo $form->error($model,'firstName'); ?>
</div>
<div class="row">
   <?php echo $form->labelEx($model,'lastName'); ?>
   <?php echo $form->textField($model,'lastName'); ?>
   <?php echo $form->error($model,'lastName'); ?>
</div>
<div class="row">
   <?php echo $form->labelEx($model,'age'); ?>
   <?php echo $form->textField($model,'age'); ?>
   <?php echo $form->error($model,'age'); ?>
</div>
<?php $this->endWidget(); ?>
<!--end a form-->

我的控制器渲染了上面的视图,这是我被卡住的地方,
我还创建了一个名为用户的模型(默认情况下,没有在其中执行任何代码)

class RegisterController extends Controller
{
   public function actionIndex()
      {
        $model = User::
        $this->render('index', array('model'=>$model));
     }
}

从我的研究中,我发现有一种东西,比如,jst-dnt不知道如何使用它链路

$post=new Post;
$post->title='sample post';
$post->content='post body content';
$post->save();

提前感谢

您需要在actionIndex:中执行

public function actionIndex()
  {
    $model = new User;
    if(isset($_POST['User']))
    {
       $model->attributes = $_POST['User'];
       if($model->save())
         //Do any stuff here. for example redirect to created user view.
    }
    $this->render('index', array('model'=>$model));
 }

我建议你阅读Yii建立博客系统教程。这是一个很好的资源,可以更好地学习yii,也可以学习任何web应用程序中最重要的部分。