Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ucfirst() class name changes in 1.6
  • I have a bunch of models that are two words, e.g. "Press Release", that I named PressRelease. As of 1.5 the ORM package interprets that to be table "press_releases", which is what I would expect. However, now with the new changes in 1.6, at least according to the coding standards, the class should now be named "Pressrelease". Which, I would expect, would then cause the ORM package to look for the table named "pressreleases". 

    Of course I could name the model Press_Release, but that would imply that it's in a directory called "press", which doesn't make much organizational sense. Is there a way around this without explicity defining $_table_name on my ORM models? Or maybe I misunderstood the new coding standards?
  • There are no new coding standards. The standards for class (segment) naming have always been ucfirst().

    Problem is that the autoloader isn't (wasn't) that strict, which allowed you to create class names like PressRelease, which were never "legal".

    Problem was that this was only the case for classnames without underscores, as soon as you have an underscore in your class name, the autoloader will spit the classname on underscore, does a ucfirst() on each of the parts, and then throws an exception because the class could not be found.

    Some Fuel dev's have violated this naming convention as well, which is how this issue came to light.
  • Are there plans to change the autoloader to enforce these standards?

    Regardless, is there a way to have ORM interpret the table name as "press_releases" without explicitly marking it or using an invalid class segment name (ie, PressRelease)?
  • HarroHarro
    Accepted Answer
    No. 1.6 is most likely the last release in the 1.x train, after it we're going to work full-blown on v2, which is going to use the composer autoloader.

    Composer follows PSR-0, which means it's case-sentitive, same case. So you can name the class whatever you want, as long as the file has exactly the same case. v2 will have a class called FuelPHP, no problem there.

    There is no way (I can think of) that can reliably convert "Pressrelease" to "press_release".

    The way to make these changes is to use a base model. In the base model, override the table() method. Make sure all your application models extend the base models, and not \Orm\Model.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion