我正在尝试在我的博客网站中添加评论模块。我所做的是:
否 1<div>
在博客文章 view.php 中添加一个以呈现 tblcomments/_form
<?php
$model_comments = new TblComments;
$this->renderPartial('/TblComments/_form',array(
'comments'=>$model_comments,
));
?>
第 2 号:这是我的 TblComments/_form.php
<
div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'tbl-comments-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model_comments); ?>
<div class="row">
<?php // echo $form->labelEx($model,'user_id'); ?>
<?php echo $form->hiddenField($model_comments,'user_id'); ?>
<?php echo $form->error($model_comments,'user_id'); ?>
</div>
<div class="row">
<?php // echo $form->labelEx($model,'post_id'); ?>
<?php echo $form->hiddenField($model_comments,'post_id'); ?>
<?php echo $form->error($model_comments,'post_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model_comments,'comment_body'); ?>
<?php echo $form->textArea($model_comments,'comment_body',array('rows'=>5,'cols'=>35)); ?>
<?php echo $form->error($model_comments,'comment_body'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model_comments->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
问题是:
Undefined variable: model_comments
PS:这个错误发生在 TblComments/_form 文件上:
<?php echo $form->errorSummary($model_comments); ?>
谁能解释我为什么这个未定义,因为我已经定义了它!