YiiMess - underscores and camelCase

Read few topics, didn’t find solution (other then some workarounds…) or any official information on that matter.

So, on ‘Fundamentals: Conventions’ page there are some nice tips:

Wow, awesome! Love this convention, using it for quite a long time!

Ahh, just like I do it - great - I’ve always followed conventions used in Yii!

Clever thing, there must be some great mapping in there that makes it possible, to use camelCase in code and underscores in DB!

Sooo, words aside, now lets face the world:

  • table "report" with column "building_id" - just like conventions says!

  • code $report -> buildingId - just like conventions says!

Output:


Property "Report.buildingId" is not defined.

What the… heck?

Is there any configuration, tweaking or settings that I can set to convince Yii to follow it’s own conventions? Or do I need to use ugly hacks and workarounds and tell Yii by myself how to handle this?

I find myself (and many others, including javascript coders) using both conventions. Usually, the underscore ones go for database fields, but also for own class properties, the camelcase version for naming functions.

There are also the $_variable and _function conventions, including the so called standard __name things regarding php standards.

It’s up to you, how did you woke up today, very_good, veryGood or class VeryGood.

I personally like the default behavior. If I see $report->building_id I know its a database property. If I have a model property that didn’t come directly from the database (maybe something computed by afterFind, etc.) I name it using camelCase. So I know that if I see $report->buildingComputed it is not a database property. Not foolproof as single word database properties are ambiguous though it does help.

I do think that "auto-formatting" building_id to buildingId would be counterintuitive though you could add this functionality to an afterFind method to map $report->building_id to $report->buildingId.

I am facing the same problem

$model->courseID

It return “courseID” is not defined any assistance please