activeLabelEx camelcasing my data.

Hi, if I send something like PO Number to activeLabelEx

($form,'PO Number') it'll be shown as Po Number

Is there anyway I can disable the camel case feature? Thanks

if PO Number is an attribute of the class of $form

you should use activeLabelEx like this:

activeLabelEx($form,'ponumberattributename')

and then in your model



public function attributeLabels()


{


    return array(


        ...


        'ponumberattributename'=>'PO Number',


        ...


    );


}

"PO Number" is retrieved from my database. It's dynamic, depending on what the user entered. I'd think it'll be problematic to declare everything in the model right?

But I hope there's a simple fix to this, if not here, maybe in the next version, because I can see there's a lot of valid cases where the activeLabelEx will wrongly lowercase the parameter.

Why lower case it anyway? The framework shouldn’t change the semantic meaning of the data, if I saved it as “PO Number” in the database, I’d expect it to come out as “PO Number” as well. I hope there’s an easy way for us to disable it. I can go change the code behind it, but that beats the point of using a framework :)

Thanks~

If it is retrieved from the database and part of the $form model you already have it, you should add only the attributelabels part. nothing else.

ActiveLabelEX fetches the label from the attributelabels methods, if you don't have a specific label declared there it is dinamically created by



	public function generateAttributeLabel($name)


	{


		return ucwords(trim(strtolower(str_replace(array('-','_'),' ',preg_replace('/(?<![A-Z])[A-Z]/', ' ', $name)))));


	}


if the name of the attribute in the DB is "PO Number" (with space???)

simply do this:



public function attributeLabels()


{


    return array(


        ...


        'PO Number'=>'PO Number',


        ...


    );


}


It feels really pointless, but usually in the db you should have an attribute named for example po_number

the default label will be "Po Number" created by generateAttributeLabel

while if you wanted it different you should do:



public function attributeLabels()


{


    return array(


        ...


        'po_number'=>'PO Number',


        ...


    );


}


It is more clear now?

I have a table with a column called parameter1, parameter2 and so on.

Each of the parameterX column stores the parameter name.

In my case, the table Report has a column parameter1 with the value "PO Number"

Another row may have PL Number as the data inside parameter1.

my function attributeLabels is like this

public function attributeLabels()


	{


		return array(


			'reportID'=>'Report ',


			'reportName'=>'Report Name',


			'parameter1'=>'Parameter 1',


			'parameter2'=>'Parameter 2',

I'm actually creating a runtime form, based on what the user entered into the database, so I don't think adding XYZ=XYZ in the attributeLabels will work. As I do not know what 'fields' the end user have entered.

Any other ways around this?

I guess you should extend your model class CFormModel/CActiveRecord and override generateAttributeLabel() to return a label of your choice.

Populate your runtime form from an instance of the extended class. (No guarantees, though. Not tested.)

/Tommy

Or you could try using label() instead

Yeah, you should override generateAttributeLabel().

Thanks… so far so good with yii :)