Fatal Error: Call To A Member Function Isattributerequired() On A Non-Object

I get an error

Fatal error: Call to a member function isAttributeRequired() on a non-object in C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php on line 1414.

I have two tables Party and customers, I want edit party view in one form with customers fields

in my controller




public function actionUpdate($id)

	{

		//$party_form = new Party;

		//$customer_form = new Customer;

		

		$model=$this->loadModel($id);

		$customer_form=$this->loadCusModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Party'], $_POST['Customer']))

		{

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

			$customer_form->attributes=$_POST['Customer'];

			

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('update',array(

			'model'=>$model,

			'customer_form'=>$customer_form,

		));

	}

........

public function loadModel($id)

	{	

		$model=Party::model()->with()->findByPk((int)$id);

		//$model=Party::model()->with(array('customer'=> array('select'=>'first_name, mobile, phone, type')))->findByPk($id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}

	

	

	public function loadCusModel($id)

	{	

		

		$customer_form=Customer::model()->with()->findByPk($id);


		/*

		$cmd = Yii::app()->db->createCommand();

		$cmd->select = 'party.account_title';

		$cmd->from = 'customer, party';

		$cmd->where = 'customer.id=party.customer_id';

		$cmd->andWhere("party.id=$id");

		$row = $cmd->queryRow();

		

		$customer_form=$row;

		if($customer_form===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $party_form;

		

		*/

		if($customer_form===null) {

			throw new CHttpException(404,'The requested page does not exist.');

		return $customer_form;

			

			

		}

	

		

	}




In update.php




<?php

/* @var $this PartyController */

/* @var $model Party */


$this->breadcrumbs=array(

	'Parties'=>array('index'),

	$model->id=>array('view','id'=>$model->id),

	'Update',

);


$this->menu=array(

	array('label'=>'List Party', 'url'=>array('index')),

	array('label'=>'Create Party', 'url'=>array('create')),

	array('label'=>'View Party', 'url'=>array('view', 'id'=>$model->id)),

	array('label'=>'Manage Party', 'url'=>array('admin')),

);

?>


<h1>Update Party <?php echo $model->id; ?></h1>


<?php $this->renderPartial('_formUpd', array('model'=>$model, 'customer_form'=>$customer_form)); ?>




and _formUpd.php




<?php

/* @var $this PartyController */

/* @var $model Party */

/* @var $form CActiveForm */

?>


<div class="form">


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

	'id'=>'party-formUpd',

	// Please note: When you enable ajax validation, make sure the corresponding

	// controller action is handling ajax validation correctly.

	// There is a call to performAjaxValidation() commented in generated controller code.

	// See class documentation of CActiveForm for details on this.

	'enableAjaxValidation'=>false,

	'htmlOptions' => array(

			'autocomplete' => 'off',

			

	

	)

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>

    <?php //echo $form->errorSummary($customer_form); ?>

    

    <div class="row">

		<?php echo $form->labelEx($customer_form,'first_name'); ?>

		<?php echo $form->textField($customer_form,'first_name',array('size'=>30,'maxlength'=>30, 'style' => 'text-transform:uppercase')); ?>

		<?php echo $form->error($customer_form,'first_name'); ?>

	</div>


	<div class="row">

		<?php //echo $form->labelEx($model,'last_name'); ?>

		<?php //echo $form->textField($model,'last_name',array('size'=>30,'maxlength'=>30, 'style' => 'text-transform:uppercase')); ?>

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

	</div>

    

	<div class="row">

		<?php echo $form->labelEx($model,'account_title'); ?>

		<?php echo $form->textField($model,'account_title',array('size'=>60,'maxlength'=>80, 'style' => 'text-transform:uppercase')); ?>

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

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'mobile'); ?>

		<?php echo $form->textField($model,'mobile',array('size'=>20,'maxlength'=>20)); ?>

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

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'phone'); ?>

		<?php echo $form->textField($model,'phone',array('size'=>20,'maxlength'=>20)); ?>

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

	</div>


	

	<div class="row buttons">

		<?php //echo CHtml::submitButton($party_form->isNewRecord ? 'Create' : 'Save'); ?>

        <?php

        $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Submit', 'size'=>'large'));

?>

	</div>


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


</div><!-- form -->




Please Help..




A full stack trace should point you to the exact line where you pass a variable to CHtml that is supposed to be a model (object) but is either undefined or null.

Thanks for reply, I did not understand error in trace code.

here is full tace code.


22:03:59.309843 	trace 	system.CModule 	


Loading "log" application component

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.314275 	trace 	system.CModule 	


Loading "bootstrap" application component

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.315853 	trace 	system.CModule 	


Loading "clientScript" application component

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\Bootstrap.php

(487)

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\Bootstrap.php

(167)

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.318286 	trace 	system.CModule 	


Loading "assetManager" application component

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\Bootstrap.php

(473)

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\packages.php

(15)

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\Bootstrap.php

(218)


22:03:59.319735 	trace 	system.CModule 	


Loading "request" application component

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\Bootstrap.php

(478)

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\packages.php

(15)

in

C:\xampp\htdocs\newApp\protected\extensions\bootstrap\components\Bootstrap.php

(218)


22:03:59.323404 	trace 	system.CModule 	


Loading "urlManager" application component

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.330316 	trace 	system.web.filters.CFilterChain 	


Running filter PartyController.filteraccessControl()

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.331042 	trace 	system.CModule 	


Loading "user" application component

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.332376 	trace 	system.CModule 	


Loading "session" application component

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.338603 	trace 	system.db.ar.CActiveRecord 	


Party.findByPk()

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (184)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (114)

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.338679 	trace 	system.CModule 	


Loading "db" application component

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (184)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (114)

in C:\xampp\htdocs\newApp\index.php (13)


22:03:59.339900 	trace 	system.db.CDbConnection 	


Opening DB connection

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (184)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (114)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.372518 	trace 	system.db.CDbCommand 	


Querying SQL: SHOW FULL COLUMNS FROM `party`

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (184)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (114)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.382750 	trace 	system.db.CDbCommand 	


Querying SQL: SHOW CREATE TABLE `party`

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (184)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (114)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.385888 	trace 	system.db.CDbCommand 	


Querying SQL: SELECT * FROM `party` `t` WHERE `t`.`id`='1' LIMIT 1

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (184)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (114)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.388562 	trace 	system.db.ar.CActiveRecord 	


Customer.findByPk()

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (195)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (115)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.388931 	trace 	system.db.CDbCommand 	


Querying SQL: SHOW FULL COLUMNS FROM `customer`

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (195)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (115)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.396218 	trace 	system.db.CDbCommand 	


Querying SQL: SHOW CREATE TABLE `customer`

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (195)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (115)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.397087 	trace 	system.db.CDbCommand 	


Querying SQL: SELECT * FROM `customer` `t` WHERE `t`.`id`='1' LIMIT 1

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (195)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (115)

in C:\xampp\htdocs\newApp\index.php (13)


22:04:00.399543 	trace 	system.CModule 	


Loading "widgetFactory" application component

in C:\xampp\htdocs\newApp\protected\views\party\_formUpd.php (21)

in C:\xampp\htdocs\newApp\protected\views\party\update.php (21)

in C:\xampp\htdocs\newApp\protected\controllers\PartyController.php (132)

This is the application log. It should contain the error you mentioned earlier, but it doesn’t. What I meant by ‘stack trace’ was other lines printed with the error:




Fatal error: Call to a member function isAttributeRequired() on a non-object in C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php on line 1414.



It should be displayed and also should be logged in the application log.

Hi you can check both model i am sure you can not create the attributeslable on one of them so please create the function on model

for e.g


public function attributeLabels() {

		return array(

			'id' => Yii::t('app', 'ID'),

			'categories_name' => Yii::t('app', 'Categories Name'),

			'categories_image' => Yii::t('app', 'Categories Image'),

			'created_at' => Yii::t('app', 'Created At'),

			'status' => Yii::t('app', 'Status'),

			'rkAdvertiserCategories' => null,

		);

	}



I check both model I have already defined attributeLabels() method. when I use var_dump($customer_form) for testing, return NULL. var_dump($model) return Object Party{…}. If I change in Controller $customer_form=$this->loadModel($id) & $$model=$this->loadCusModel($id) then I receive $customer_form return object and $model return NULL. e.g loadCusModel() not load the attributes and return NULL. Where going on wrong Please help.

Hi please change line like in party model i guess you insert the cust_id


$model=$this->loadModel($id);

$customer_form=$this->loadCusModel($model->cust_id,'Customer');

Ok thanks I found out solution elsewhere, problem was in my loadCusModel() method.


 public function loadCusModel($id)

        {       

                

                $customer_form=Customer::model()->with()->findByPk($id);


                if($customer_form===null) {

                        throw new CHttpException(404,'The requested page does not exist.');

                return $customer_form;

                        

                        

                }



move the return line outside of if statement. like:


if($customer_form===null) {

                        throw new CHttpException(404,'The requested page does not exist.');

                

                        

                        

                }

return $customer_form;