I have a model EmployeeEducation which describes the educational background of a specific employee. I want to display all retrieved information through a table view. If I use findByAttributes it returns the latest entry, but findAllByAttributes returns an array. I don’t know if I’m doing it right by using foreach to separate data, also the part to submit the form:
<?php echo CHtml::submitButton($educ[0]->isNewRecord ? 'Create' : 'Save'); ?>
Will $_POST["EmployeeEducation"] contain all $educ or $educ[0] only?
This is what it currently looks like:
Below is my view _education.php.
<?php
$educ=EmployeeEducation::model()->findAllByAttributes(array('employee_id'=>$model->employee_id));
$form=$this->beginWidget('CActiveForm', array(
'enableClientValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true),
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<p>III. Educational Background</p>
<table>
<tr>
<th><?php echo $form->labelEx($educ[0],'level'); ?></th>
<th><?php echo $form->labelEx($educ[0],'school_name'); ?></th>
<th><?php echo $form->labelEx($educ[0],'degree_course'); ?></th>
<th><?php echo $form->labelEx($educ[0],'year_graduated'); ?></th>
<th><?php echo $form->labelEx($educ[0],'highest_grade'); ?></th>
<th><?php echo $form->labelEx($educ[0],'from_year'); ?></th>
<th><?php echo $form->labelEx($educ[0],'to_year'); ?></th>
<th><?php echo $form->labelEx($educ[0],'honors_received'); ?></th>
</tr>
<?php
foreach ($educ as $val)
echo '<tr>
<td>'. $form->dropDownList($val,'level',EmployeeEducation::model()->level) .'</td>
<td>'. $form->textField($val,'school_name') .'</td>
<td>'. $form->textField($val,'degree_course') .'</td>
<td>'. $form->textField($val,'year_graduated') .'</td>
<td>'. $form->textField($val,'highest_grade') .'</td>
<td>'. $form->textField($val,'from_year') .'</td>
<td>'. $form->textField($val,'to_year') .'</td>
<td>'. $form->textField($val,'honors_received') .'</td>
</tr>';
?>
</table>
<div class="row buttons">
<?php echo CHtml::submitButton($educ[0]->isNewRecord ? 'Create' : 'Save'); ?>
<?php echo CHtml::resetButton('Reset'); ?>
</div>
<?php $this->endWidget(); ?>
I also need to place an [ADD] button to dynamically create a new row to store additional educational information (ie. for multiple graduate studies).