I’m having an awkward situation. I have a model in wich 3 other models are used. These 3 models are all of the same class.
CHtml uses resolveName to assemble the NAME for the html elements. In this example, if I use CHtml to build up the form, the NAME’s would be 3 times the same. This is not what I want.
What I need is CHtml::resolveName not calling ‘get_class’ but calling $model->resolveName(), wich in turn can be overloaded.
(Yes I know, I’m getting troubles with the labelnames, but I can solve that by overloading CFormModel::attributeLabels() or using a fieldset)
e.g.
class meter extends CFormModel
{
public $startvalue;
public $endvalue;
}
class myclass extends CFormModel
{
public $meter1;
public $meter2;
public $meter3;
}
//Form
echo CHtml::activeLabel($model->meter1,'startvalue') .
CHtml::activeTextField($model->meter1,'startvalue');
echo CHtml::activeLabel($model->meter1,'endvalue') .
CHtml::activeTextField($model->meter1,'endvalue');
echo CHtml::activeLabel($model->meter2,'startvalue') .
CHtml::activeTextField($model->meter2,'startvalue');
echo CHtml::activeLabel($model->meter2,'endvalue') .
CHtml::activeTextField($model->meter2,'endvalue');
echo CHtml::activeLabel($model->meter3,'startvalue') .
CHtml::activeTextField($model->meter3,'startvalue');
echo CHtml::activeLabel($model->meter3,'endvalue') .
CHtml::activeTextField($model->meter3,'endvalue');
@Sebas: I have read the post about tabular form input. However this is not I want to do. I don’t have an array of models and I don’t have a relationship like 1 OrderHeader to many OrderLines.
The relationship I have, is 1 Room to 1 possible electric meter (meter1), to 1 possible water meter (meter2), to 1 possible gas meter (meter3). I have put all the different meters into one model, because they all share the same attributes.
The room has 3 attributes wich define if the meter is present or not: electricmeterpresent, watermeterpresent, gasmeterpresent.
So what I’m dealing with is not tabular input. The solution for the tabular form input is also programmed in CHtml::resolveName. Actually the only thing I want to do is to influence the NAME of a FORM/INPUT. The ID is already derived from the NAME in the CHtml class.
I’m guessing the only thing I can do at this moment is to program my own activeLabel and activeField, so I can determine my own FORM/NAME.
This is why I proposed to have CHTML::resolveName call a new function $model->resolveName. This way I can allways influence the NAME and I don’t have to program half of the CHtml class into my own class.