开发者

there is issue in yii " comment form view in post list"

I tried to bring the comment form in the post view list where user can put a comment . my code which I am write for the above problem ...

<h5>Add your Comment</h5>

    <?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
        <div class="flash-success">
            <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
        </div>
    <?php else: ?>

       <?php $this->renderPartial('/comment/_form',array(
            'model'=>$comment
        )); ?>

    <?php endif; ?>

"The _form contain....."

<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->e开发者_开发知识库rrorSummary($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>
  <div class="row">
    <?php echo $form->labelEx($model,'author'); ?>
    <?php echo $form->textField($model,'author',array('size'=>60,'maxlength'=>128)); ?>
    <?php echo $form->error($model,'author'); ?>
  </div>

It gives the error "Undefined variable: comment "


You need to define $comment. You are trying to pass a model to the form. This is usually a model of a database table. It looks like you are using active form. That means you are using the Active Record model in Yii. You should have a model that covers your comment table. If you need to know how to create a model you can find out how to use Gii here.

If you already have a comment model then you just need to define the model. Something like:

$comment = new Comment();
$this->renderPartial('/comment/_form',array('model'=>$comment));

It looks like this is a view that sometimes calls another view. You could define the $comment variable in the controller that calls the original view. You would just have to pass the comment variable into the original view as well as the second one.


Without knowing exactly where the error occurs, it seems to me that the most logical location is in this snippet:

<?php $this->renderPartial('/comment/_form',array(
    'model'=>$comment
)); ?>

The solution would then probably be to replace $comment by 'Comment' (or something similar, I'm not really familiar with Yii).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜