Contact form reuse in any pages

Hi guys i’ve problems creating a contact form portlet for reusing in all my application pages so my answer is:

This is the right way for reuse contact form in any pages or i wrong?

anyone else do this and can explain me what have done?

the controller is the SiteController that yiic create by default and my ContactForm component is this:



class ContactForm extends CPortlet


    public $title="Contact Us";

    protected function  renderContent() {

        $form = new ContactForm;

            if(isset ($_POST['ContactForm']))




                    $this->controller->refresh ();


            $this->render('contactForm', array('form'=>$form));



the view in the component/views folder is: contactForm.php

<?php echo CHtml::beginForm(); ?>

<div class="row">

    <?php echo CHtml::activeLabel($form,'name'); ?>


 <?php echo CHtml::activeTextField($form,'name') ?>

<?php echo CHtml::error($form,'name'); ?>  


<div class="row">

    <?php echo CHtml::submitButton('Submit'); ?>


<?php echo CHtml::endForm(); ?>

i use in index view this:

<?php $this->widget('ContactForm'); ?>

that’s give me an CException error: ContactForm and its behaviors do not have a method or closure named “getAttributeLabel”.

i don’t undestand cause i’ve done login portlet like in blog tutorial and works but this is not the same?

help me please i’m new in Yii.


Yii requires unique class name.

your Portlet under components\ContactForm.php shares the same name as models\ContactForm.php. rename your portlet and it should work.

Thanks a lot rootbear, I rename an it works!!!