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'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List Users', 'url'=>array('index')),
array('label'=>'Manage Users', 'url'=>array('admin')),
);
?>
<h1>Create Users</h1>
<?php $this->renderPartial(’_form’,
array(
'users'=>$users,
'userdetails'=>$userdetails,
'departments'=>$departments,
'sections'=>$sections,
'positions'=>$positions,
'roles'=>$roles,
)); ?>
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'=>'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'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($users,$userdetails,$departments,$sections,$positions,$roles); ?>
<div class="row">
<?php echo $form->labelEx($users,'user_aname'); ?>
<?php echo $form->textField($users,'user_aname',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($users,'user_aname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($userdetails,'usrdtl_fname'); ?>
<?php echo $form->textField($userdetails,'usrdtl_fname',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($userdetails,'usrdtl_fname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($userdetails,'usrdtl_mname'); ?>
<?php echo $form->textField($userdetails,'usrdtl_mname',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($userdetails,'usrdtl_mname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($userdetails,'usrdtl_lname'); ?>
<?php echo $form->textField($userdetails,'usrdtl_lname',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($userdetails,'usrdtl_lname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($userdetails,'usrdtl_mobileno'); ?>
<?php echo $form->textField($userdetails,'usrdtl_mobileno',array('size'=>13,'maxlength'=>13)); ?>
<?php echo $form->error($userdetails,'usrdtl_mobileno'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($userdetails,'usrdtl_email'); ?>
<?php echo $form->textField($userdetails,'usrdtl_email',array('size'=>60,'maxlength'=>245)); ?>
<?php echo $form->error($userdetails,'usrdtl_email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($departments,'dept_name'); ?>
<?php $data = Departments::model()->findAll(array('order'=>'dept_name'));
$data = CHtml::listData($data,'dept_id','dept_name');
echo CHtml::dropDownList('department', $departments,$data,
array(
'prompt'=>'Select Department',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('updatesection'),
'update'=>'#section',
)));
?>
</div>
<div class="row">
<?php echo $form->labelEx($sections,'sec_name'); ?>
<?php echo $form->dropDownList($sections,'sec_name', CHtml::listData(Sections::model()->findAll(array('order'=>'sec_name')), 'sec_id', 'sec_name'), array('empty'=>'Select Sections..'));
?>
</div>
<div class="row">
<?php echo $form->labelEx($positions,'pos_name'); ?>
<?php echo $form->dropDownList($positions,'pos_name', CHtml::listData(Positions::model()->findAll(array('order'=>'pos_name')), 'pos_id', 'pos_name'), array('empty'=>'Select Position..'));
?>
</div>
<div class="row">
<?php echo $form->labelEx($roles,'role_name'); ?>
<?php echo $form->dropDownList($roles,'role_name', CHtml::listData(Roles::model()->findAll(array('order'=>'role_name')), 'role_id', 'role_name'), array('empty'=>'Select Role..'));
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($users->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?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!!