
Originally Posted by
the Enlightened One
It would only need a simple PHP table for the rates, and they could be generated right into the form,
LOL, simple php table in the form... that's rich WG! <tears of laughter>
The framework is designed to make such a task 'simple'... But I am having a very difficult time with this simple task.
See, the problem is that the jobClass table and the serviceItem table are not with-in the same 'Class' of the ServiceRequest form. Nor do the two pre-populated tables have a relation to the serviceRequest table which holds the user input.
Forwhatever reason, I can pull information from those other tables into the Request form but only through the use of CHtml::helper classes which consist of the dropDownBoxes and listData and such. Those are appropriate for form inputs but not for informational text.
The DOC reference for listData used in this listBox said to use query however after seeking help on their forum it was findAllbySql with the CONCAT which made it work. :eyeroll:
Code:
<div id="ServiceRequest_selection">
<?php echo CHtml::activeListBox($ServiceRequest, 'selection',
CHtml::listData(ServiceItem::model()->findAllbySql(
'SELECT itemId, CONCAT(itemId, ". ", itemName) as listBoxData FROM serviceItem'),'itemId', 'listBoxData'), array('empty'=>'shift-key select multiple','prompt'=>'Select All that Apply', 'multiple'=>'multiple','style'=>'width:auto; height:138px;' )); ?>
</div><!-- eof ServiceRequest_selection -->
When I try to call info from those other tables using a db query, I get errors such as unassigned variables and such or just the simple text of 'Array' on the page which is what this code produces...
Code:
<?php echo $data = Yii::app()->db->createCommand()
->select('classId, CONCAT(classId, " ", className, " ", hrRate) as classRates')
->from('jobClass')
->queryAll();
$res = array();
foreach ($data as $row) {
$res[$row['classId']] = $row['classRates'];
}
return $res;
?>
The documentation and other pages offer explanations of how to use the getter and setter functions to assign variables of those other tables which would be usable from anywhere in the application but I keep trying and fail.
For the classRates, I have resorted to setting application-level parameters in the config file that can be accessed using...
Code:
Yii::app()->params['paramName']
I just had to see a working result after all of my failures!
But I will keep trying to use the setter and getter methods so that the serviceItems with the timeEstimate can be pulled in from the table, for informational and manipulating purposes. I will ask for help with that on the Yii forum...
The input received in this thread is greatly appreciated, it has helped to guide my steps and evaluate options. I'll be back, hopefully with working getter and setter methods!