I’ve hit a bit of an impasse with something - I’m trying to assign my own text for a label in a form and I had a look through the API for something, settling on generateAttributeLabel and getAttributeLabel before realising I was doing the renderDynamicInternal thing - looking for a programmatic solution for something which can be solved just by manually writing a <label> tag into the view, or using CHtml::label instead of CHtml::activeLabel.
The problem is, I can’t set the ‘for’ property, because I don’t know what the ID of the activeTextBox is going to be until after I’ve created it, and CHtml::resolveNameId is protected so I can’t use CHtml’s method of creating the ID.
Using activeLabel, which gives me a label I don't want (Artistname): <div class="simple"> <?php echo CHtml::activeLabel($artist,'artistName'); ?> <?php echo CHtml::activeTextField($artist,'artistName') ?> </div> Using label, which means I can't set the 'for' attribute: <div class="simple"> <?php echo CHtml::label('Artist Name', '?); ?> <?php echo CHtml::activeTextField($artist,'artistName') ?> </div>
Should I go back to hacking around on getAttributeLabel? It feels like it would be neater if I could just get the ID of the text field somehow.
Also, would it be worth modifying generateAttributeLabel to deal with camel casing with something like this:
return trim(ucwords(strtolower(preg_replace('/[A-Z_]/', ' ', $name))));
or would the use of a regexp be unacceptable from a performance perspective?