Renderpartial - Geterrors() On A Non-Object

I am getting…Fatal error: Call to a member function getErrors() on a non-object in /Applications/XAMPP/yii/framework/web/helpers/CHtml.php on line 1705. Please give me some guidance thanks.

I have a view company.php




<?php $this->widget('bootstrap.widgets.TbTabs', array(

  'type'=>'tabs',

  'placement'=>'left',

  'tabs'=>array(

    array('label'=>'About','content'=>$this->renderPartial('about', array('model'=>$model), true), 'active'=>true),

    array('label'=>'Contact','content'=>$this->renderPartial('contact', array('model'=>$model), true)),

  ),

)); ?>



Then from yiic generated code I have SiteController.php




	/**

	 * Displays the contact page

	 */

	public function actionContact()

	{

		$model=new ContactForm;

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

		{

			$model->attributes=$_POST['ContactForm'];

			if($model->validate())

			{

				$headers="From: {$model->email}\r\nReply-To: {$model->email}";

				mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);

				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');

				$this->refresh();

			}

		}

		$this->render('contact',array('model'=>$model));

	}



And yiic generated contact.php




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

	'id'=>'contact-form',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>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,'name'); ?>

		<?php echo $form->textField($model,'name'); ?>

		<?php echo $form->error($model,'name'); ?>

	</div>



Where do you render "company" view? In "actionCompany" method of the SiteController? If so, would you please post your code of the "actionCompany"?

Yes actionCompany is in SiteController. Thanks for reply.




	public function actionCompany()

	{

		// renders the view file 'protected/views/site/company.php'

		$this->render('company');

	}



You have to supply the "model" to the view.




                $this->render('company',array('model'=>$model));



And, your actionCompany should be almost the same with actionContact, otherwise the contact mail won’t be sent.

I updated actionCompany and it works. Except I want the flash message to render on the contact tab and not refresh company.php and return to the ‘active’ tab, I’ve tried some variations with renderPartial. Any suggestions? Thanks again.




	public function actionCompany()

	{

		$model=new ContactForm;

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

		{

			$model->attributes=$_POST['ContactForm'];

			if($model->validate())

			{

				$headers="From: {$model->email}\r\nReply-To: {$model->email}";

				mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);

				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');

				$this->refresh();

			}

		}

		

		// renders the view file 'protected/views/site/company.php'

		 $this->render('company',array('model'=>$model));

	}



You can check if the flash message is set or not in ‘company’ view. So why don’t you set the selected tab according to it?

Thanks for the help. Added this to company.php




<?php if(Yii::app()->user->hasFlash('company')): ?>

 

<?php Yii::app()->user->setFlash('success', '<strong>Thank you for contacting us.</strong> We will respond to you as soon as possible.');

$this->widget('bootstrap.widgets.TbAlert', array(

'block'=>true, // display a larger alert block?

'fade'=>true, // use transitions?

'alerts'=>array( // configurations per alert type

'success'=>array('block'=>true, 'fade'=>true,), // success, info, warning, error or danger

),

)); ?>

 

<?php endif; ?>