CActiveForm has an extra endWidget() call in its view.

I tried to use $form=$this->beginWidget(‘CActiveForm’); in a CPortlet class but than when I placed it in one of my layouts as $this->widget(‘application.components.Email’); I got the following error:



CActiveForm has an extra endWidget() call in its view.

Source File


00191:      * @return CWidget the widget just ended running

00192:      * @throws CException if an extra endWidget call is made

00193:      * @see beginWidget

00194:      */

00195:     public function endWidget($id='')

00196:     {

00197:         if(($widget=array_pop($this->_widgetStack))!==null)

00198:         {

00199:             $widget->run();

00200:             return $widget;

00201:         }

00202:         else

00203: throw new CException(Yii::t('yii','{controller} has an extra endWidget({id}) call in its view.',

00204:                 array('{controller}'=>get_class($this),'{id}'=>$id)));

00205:     }


00207:     /**

00208:      * Begins recording a clip.

00209:      * This method is a shortcut to beginning {@link CClipWidget}.

00210:      * @param string the clip ID.

00211:      * @param array initial property values for {@link CClipWidget}.

00212:      */

00213:     public function beginClip($id,$properties=array())

00214:     {

00215:         $properties['id']=$id;

is that an expected behaviour?

replacing the CActiveForm with the usual CHtml::beginFrom()…etc fixed the issue but now I am unable to use the handy ajax validation feature of the CActiveFrom widget.

All solution suggestions are welcome.



You need to check your code… somewhere you have a call to endWidget() that is not needed…

For example

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>



<?php $this->endWidget(); ?>   // <--- closes the above widget 



<?php $this->endWidget(); ?>   // <--- this one will cause the error

When I start pulling my hair out over this one, I soon realize that I’ve called $form->endWidget() instead of $this->endWidget()…

I suffered the same by a human error (in the middle of a system change from Linux to Windows, where some day before). It’s unintentionally deleting the php tag in a opening tag of a line <?php.

Wrong code without php in the first open tag, like <?

<?php /* @var $this Controller */ ?>





        <?php echo $content; ?>


<?php $this->endContent(); ?>

Correct code with php literal

<?php /* @var $this Controller */ ?>





        <?php echo $content; ?>


<?php $this->endContent(); ?>