Property "sections.class" Is Not Defined.

I have a problem in adding to database the multiple models that i create in the UsersController.

It gives me an error of -

CException Property "Sections.class" is not defined.

My Project has Users, Userdetails, Department, Section, Position, Role

This is my UsersController code for actionCreate()

public function actionCreate()

{


	$users = new Users;


	$userdetails = new Userdetails;


	$departments = new Departments;


	$sections = new Sections;


	$positions = new Positions;


	$roles = new Roles;


	// Uncomment the following line if AJAX validation is needed


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





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


	{


		$users->attributes = $_POST['Users'];


		$userdetails->attributes = $_POST['Userdetails'];


		$sections->attributes = $_POST['Sections'];


		$positions->attributes = $_POST['Positions'];


		$roles->attributes =$_POST['Roles'];


		


		$users->user_apassword = md5($users->user_aname);


		$temp = $sections->sec_id;


		$users->user_secid = $temp;


		


		$temp = $roles->role_id;


		$users->user_roleid = $temp;





		$users->save();


		


		$temp = $positions->pos_id;


		$userdetails->usrdtl_posid = $temp;


		


		$temp = $users->user_id;


		$userdetails->usrdtl_id = $temp;


		


		$userdetails->save();


		


	}





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


		'users'=>$users,


		'userdetails'=>$userdetails,


		'departments'=>$departments,


		'sections'=>$sections,


		'positions'=>$positions,


		'roles'=>$roles,				


	));


}

This my code for create.php

<?php

/* @var $this UsersController */

/* @var $model Users */

$this->breadcrumbs=array(

'Users'=&gt;array('index'),


'Create',

);

$this->menu=array(

array('label'=&gt;'List Users', 'url'=&gt;array('index')),


array('label'=&gt;'Manage Users', 'url'=&gt;array('admin')),

);

?>

<h1>Create Users</h1>

<?php $this->renderPartial(’_form’,

	array(


			'users'=&gt;&#036;users,


			'userdetails'=&gt;&#036;userdetails,


			'departments'=&gt;&#036;departments,


			'sections'=&gt;&#036;sections,


			'positions'=&gt;&#036;positions,


			'roles'=&gt;&#036;roles,


		)); ?&gt;

and this is the code on my _form.php

<?php

/* @var $this UsersController */

/* @var $model Users */

/* @var $form CActiveForm */

?>

<div class="form">

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

'id'=&gt;'users-form',


// 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'=&gt;false,

)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;





&lt;?php echo &#036;form-&gt;errorSummary(&#036;users,&#036;userdetails,&#036;departments,&#036;sections,&#036;positions,&#036;roles); ?&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;users,'user_aname'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;users,'user_aname',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;users,'user_aname'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;userdetails,'usrdtl_fname'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;userdetails,'usrdtl_fname',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;userdetails,'usrdtl_fname'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;userdetails,'usrdtl_mname'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;userdetails,'usrdtl_mname',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;userdetails,'usrdtl_mname'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;userdetails,'usrdtl_lname'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;userdetails,'usrdtl_lname',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;userdetails,'usrdtl_lname'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;userdetails,'usrdtl_mobileno'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;userdetails,'usrdtl_mobileno',array('size'=&gt;13,'maxlength'=&gt;13)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;userdetails,'usrdtl_mobileno'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;userdetails,'usrdtl_email'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;userdetails,'usrdtl_email',array('size'=&gt;60,'maxlength'=&gt;245)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;userdetails,'usrdtl_email'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;departments,'dept_name'); ?&gt;


	&lt;?php &#036;data = Departments::model()-&gt;findAll(array('order'=&gt;'dept_name')); 


		  &#036;data = CHtml::listData(&#036;data,'dept_id','dept_name'); 


		  echo CHtml::dropDownList('department', &#036;departments,&#036;data,


		  array(


		  	'prompt'=&gt;'Select Department',


			'ajax' =&gt; array(


			'type'=&gt;'POST', 


			'url'=&gt;CController::createUrl('updatesection'), 


			'update'=&gt;'#section', 


			))); 


	?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;sections,'sec_name'); ?&gt;


    &lt;?php echo &#036;form-&gt;dropDownList(&#036;sections,'sec_name', CHtml::listData(Sections::model()-&gt;findAll(array('order'=&gt;'sec_name')), 'sec_id', 'sec_name'), array('empty'=&gt;'Select Sections..'));


	?&gt;                


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;positions,'pos_name'); ?&gt;


    &lt;?php echo &#036;form-&gt;dropDownList(&#036;positions,'pos_name', CHtml::listData(Positions::model()-&gt;findAll(array('order'=&gt;'pos_name')), 'pos_id', 'pos_name'), array('empty'=&gt;'Select Position..'));


	?&gt;		


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;roles,'role_name'); ?&gt;


    &lt;?php echo &#036;form-&gt;dropDownList(&#036;roles,'role_name', CHtml::listData(Roles::model()-&gt;findAll(array('order'=&gt;'role_name')), 'role_id', 'role_name'), array('empty'=&gt;'Select Role..'));


	?&gt;	  


	


&lt;/div&gt;





&lt;div class=&quot;row buttons&quot;&gt;


	&lt;?php echo CHtml::submitButton(&#036;users-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;


&lt;/div&gt;

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

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

My objective is to save the data in all models that i created in my UsersController,

Hope someone could help solve my problem! Thanks!!

I see a lot of issues here.

  1. What’s the meaning of these lines?

$temp = $sections->sec_id;

$users->user_secid = $temp;


$temp = $roles->role_id;

$users->user_roleid = $temp;

Why do you need another variable?

  1. I don’t see any place where $sections->sec_id, $roles->role_id etc are set.

  2. Your exception "CException Property "Sections.class" is not defined" may be caused by validation rules, check the Sections model class.

Thanks ORey for the fast response on my post.

$temp = $sections->sec_id;

$users->user_secid = $temp;

$temp = $roles->role_id;

$users->user_roleid = $temp;

These are models Sections and Roles. I post the selected value on the dropdown on both Roles and Section and placed it on the Users table because it has relation to them.

What will I check on the validation rules under Section Class? the method rules()?

I mean what’s the use of $temp variable.

In any case,


$form->dropDownList($sections,'sec_name'

should be


$form->dropDownList($sections,'sec_id'

I suppose, otherwise you’ll have empty sec_id (this should raise a notice)

Yes, start at rules(). I think you have a validation rule for field ‘class’ or something similar, because of typo or error.

It seems to problem is that my post value is not correct. In my Sections Model, i don’t have any class attribute, I only got sec_id, sec_code, sec_name, sec_deptid under it. So im confused why it is displaying an error Sections.Class .

I am still debugging the program thanks for the help!

Check this link

http://www.larryullman.com/forums/index.php?/topic/2593-yii-case-sensitivity-causes-cexception-property-is-not-defined/