我已经在我的帖子视图下面的评论表单,但问题是,它不能通过评论表单存储数据到数据库下面的帖子视图。我的代码注释表单....
<h5>Add your Comment</h5>
<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
<?php else: ?>
<?php $comment= new Comment();
$this->renderPartial('/comment/_form',array('model'=>$comment,
)); ?>
和_form的代码是
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'comment-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'content'); ?>
<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'content'); ?>
</div>
我想从评论表单中存储数据,这是在post视图
我不是100%确定你在这里问什么,但我认为你是问如何保存数据从表单提交?在您的控制器中,在呈现注释表单的操作中,使用:
$model = new Comment;
if(isset($_POST['Comment'])){
$model->attributes=$_POST['Comment'];
$model->save();
}
您应该检查gii工具(http://yiitutorials.net/easy/using-yiis-gii-tool),它将帮助您生成模型,表单和保存表单数据的操作。希望这回答了你的问题,如果没有,我道歉!
在下载的源代码中你可以找到博客演示,它有一个很好的例子如何使用注释:D