开发者

fill data to the database from comment form of post view in yii

i have already the comment form bellow my post view , but the problem is that it can not be store the data by comment form to the database which is bellow post view. My code for comment form....

<h5>Add your Comment</h5>

    <?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
        <div cla开发者_JAVA技巧ss="flash-success">
            <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
           <?php else: ?>
    <?php $comment= new Comment();
        $this->renderPartial('/comment/_form',array('model'=>$comment,
         )); ?>

and my code of _form is

<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>

i want to store data from the comment form which is in the post view.


I'm not 100% sure what you are asking here, but I think you are asking how to save the data from the form submit? In you controller, in the action that renders the comment form, use:

$model = new Comment;
if(isset($_POST['Comment'])){
    $model->attributes=$_POST['Comment'];
    $model->save();
}

You should check out the gii tool (http://yiitutorials.net/easy/using-yiis-gii-tool), it will help you generate your models, forms and action to save the form data. Hope that answered your question, apologies if it didn't!


On the downloaded source code you can find blog demo, and it has great example howto use comments :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜