Thank you so much for the reply. I did debug and try to see what’s the error but it didn’t show any error. I can’t figure out what is actually the problem is. As I mentioned earlier, I can save the first start and end time. However, I can’t save the following start and end time. Is there anything that I miss out??
my view file:
<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'course-form',
'enableAjaxValidation'=>false,
'method'=>'post',
'type'=>'horizontal',
'htmlOptions'=>array(
'enctype'=>'multipart/form-data'
)
)); ?>
<fieldset style="margin-left:10px; margin-right:10px; background-color:#FFFFE0">
<h3><p class="note">Course Details</p></h3>
<h5><p class="note">Fields with <span class="required">*</span> are required.</p></h5></br>
<?php echo $form->errorSummary($model,'Opps!!!', null,array('class'=>'alert alert-error span12')); ?>
<div class="control-group" style="margin-left:50px;>
<div class="span4">
<?php echo $form->textFieldRow($model,'code',array('class'=>'span5')); ?>
<?php echo $form->textFieldRow($model,'name',array('class'=>'span5')); ?>
<div style="margin-left:70px">
<?php echo $form->labelEx($model,'type'); ?>
<div style="margin-left:110px; margin-top:-30px">
<?php echo $form->dropDownList($model,'type', CHtml::listData(CourseType::model()->findAll(), 'type', 'type'), array('empty'=>'Please Select Course Type','style'=>'width:350px')); ?>
</div></div></br>
<?php echo $form->textFieldRow($model,'credit_hour',array('class'=>'span5')); ?>
<div style="margin-left:30px">
<?php echo $form->labelEx($model,'prerequisite'); ?>
<div style="margin-left:150px; margin-top:-30px">
<?php echo $form->textArea($model,'prerequisite',array('class'=>'span5','maxlength'=>1000)); ?>
</div></div></br>
<div style="margin-left:30px">
<?php echo $form->labelEx($model,'session'); ?>
<div style="margin-left:150px; margin-top:-30px">
<?php
$yearNow = date("Y");
$yearFrom = $yearNow - 4;
$arrYears = array();
foreach (range($yearFrom, $yearNow) as $number) {
$arrYears[$number] = $number;
}
echo $form->dropDownList($model,'session',$arrYears,array('style'=>'width:100px')); ?> / <?php
echo $form->dropDownList($model,'session2',$arrYears,array('style'=>'width:100px')); ?> - <?php
echo $form->dropDownList($model,'semester',array('Sem 1'=>'Sem 1 (Feb-May)','Sem 2'=>'Sem 2 (Sept-Jan)','Sem 3'=>'Sem 3 (Jun-July)'),array('style'=>'width:155px'));
?>
</div></div></br>
<?php echo $form->textFieldRow($model,'total_student',array('class'=>'span5')); ?>
</fieldset>
<fieldset style="margin-left:10px; margin-right:10px; background-color:#FFFFE0">
<h3><p class="note">Class Details</p></h3>
<table style="margin-top:-60px;">
<tr style="background: #FFFFB2">
<td>Class Details</td>
<td>Class 1</td>
<td>Class 2</td>
<td>Class 3</td>
<td>Class 4</td>
</br></tr>
<tr>
<td><?php echo $form->labelEx($model,'class_type'); ?></td>
<td><?php echo $form->dropDownList($model,'class_type', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>
<td><?php echo $form->dropDownList($model,'class_type1', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>
<td><?php echo $form->dropDownList($model,'class_type2', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>
<td><?php echo $form->dropDownList($model,'class_type3', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>
</br> </tr>
<tr style="background: #FFFFB2">
<td><?php echo $form->labelEx($model,'day'); ?></td>
<td><?php echo $form->dropDownList($model,'day', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>
<td><?php echo $form->dropDownList($model,'day1', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>
<td><?php echo $form->dropDownList($model,'day2', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>
<td><?php echo $form->dropDownList($model,'day3', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>
</br></tr>
<tr>
<td><?php echo $form->labelEx($model,'start'); ?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'start',
));
?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'start1',
));
?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'start2',
));
?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'start3',
));
?></td></br></tr>
<tr style="background: #FFFFB2">
<td><?php echo $form->labelEx($model,'end'); ?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'end',
));
?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'end1',
));
?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'end2',
));
?></td>
<td><?php
$this->widget('ext.timepicker.timepicker', array(
'model'=>$model,
'name'=>'end3',
));
?></td></tr>
</table>
</div></div>
</table>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'icon'=>'ok white',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'reset',
'icon'=>'remove',
'label'=>'Reset',
)); ?>
</div>
</fieldset>
<?php $this->endWidget(); ?>
</div>
my model file:
<?php
/**
* This is the model class for table "course".
*
* The followings are the available columns in table 'course':
* @property integer $id
* @property string $code
* @property string $name
* @property string $type
* @property integer $credit_hour
* @property string $prerequisite
* @property string $session
* @property string $session2
* @property string $semester
* @property integer $total_student
* @property string $class_type
* @property string $day
* @property string $start
* @property string $end
* @property string $class_type1
* @property string $day1
* @property string $start1
* @property string $end1
* @property string $class_type2
* @property string $day2
* @property string $start2
* @property string $end2
* @property string $class_type3
* @property string $day3
* @property string $start3
* @property string $end3
*/
class Course extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'course';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('code, name, type, credit_hour, session, session2, semester, total_student, class_type, day, start, end', 'required'),
array('credit_hour, total_student', 'numerical', 'integerOnly'=>true),
array('code', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,
array('name', 'length', 'max'=>100),
array('type, semester', 'length', 'max'=>50),
//array('prerequisite', 'length', 'max'=>1000),
array('session, session2', 'length', 'max'=>4),
array('class_type, day, class_type1, day1, class_type2, day2, class_type3, day3', 'length', 'max'=>20),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, code, name, type', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'code' => 'Course Code',
'name' => 'Course Name',
'type' => 'Course Type',
'credit_hour' => 'Credit Hour',
'prerequisite' => 'Course Prerequisite',
'session' => 'Session/Semester',
//'session2' => 'Session2',
//'semester' => 'Semester',
'total_student' => 'Total Student',
'class_type'=> 'Class Type',
'day' => 'Class Day',
'start' => 'Class Start',
'end' => 'Class End',
// 'class_type1' => 'Class Type1',
// 'day1' => 'Day1',
// 'start1' => 'Start1',
// 'end1' => 'End1',
// 'class_type2' => 'Class Type2',
// 'day2' => 'Day2',
// 'start2' => 'Start2',
// 'end2' => 'End2',
// 'class_type3' => 'Class Type3',
// 'day3' => 'Day3',
// 'start3' => 'Start3',
// 'end3' => 'End3',
);
}
public function afterSave() {
if($this->isNewRecord){
$model2 = new CourseClass();
$model2->course_id = $this->id;
$model2->class_type = $this->class_type;
$model2->day = $this->day;
$model2->start = $this->start;
$model2->end = $this->end;
$model2->class_type1 = $this->class_type1;
$model2->day1 = $this->day1;
$model2->start1 = $this->start1;
$model2->end1 = $this->end1;
$model2->class_type2 = $this->class_type2;
$model2->day2 = $this->day2;
$model2->start2 = $this->start2;
$model2->end2 = $this->end2;
$model2->class_type3 = $this->class_type3;
$model2->day3 = $this->day3;
$model2->start3 = $this->start3;
$model2->end3 = $this->end3;
$model2->save(false);
}
}
private $idCache;
public function beforeDelete()
{
$this->idCache = $this->id;
return parent::beforeDelete();
}
public function afterDelete()
{
$criteria = new CDbCriteria(array(
'condition' =>'id=:id',
'params' => array(
':id' => $this->idCache),
));
$children = CourseTimetable::model()->findAll($criteria);
foreach ($children as $child)
{
$child->delete();
}
parent::afterDelete();
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('code',$this->code,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('type',$this->type,true);
$criteria->compare('credit_hour',$this->credit_hour);
$criteria->compare('prerequisite',$this->prerequisite,true);
$criteria->compare('session',$this->session,true);
$criteria->compare('session2',$this->session2,true);
$criteria->compare('semester',$this->semester,true);
$criteria->compare('total_student',$this->total_student);
$criteria->compare('class_type',$this->class_type,true);
$criteria->compare('day',$this->day,true);
$criteria->compare('start',$this->start,true);
$criteria->compare('end',$this->end,true);
$criteria->compare('class_type1',$this->class_type1,true);
$criteria->compare('day1',$this->day1,true);
$criteria->compare('start1',$this->start1,true);
$criteria->compare('end1',$this->end1,true);
$criteria->compare('class_type2',$this->class_type2,true);
$criteria->compare('day2',$this->day2,true);
$criteria->compare('start2',$this->start2,true);
$criteria->compare('end2',$this->end2,true);
$criteria->compare('class_type3',$this->class_type3,true);
$criteria->compare('day3',$this->day3,true);
$criteria->compare('start3',$this->start3,true);
$criteria->compare('end3',$this->end3,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Course the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}