5

I'm using CakePHP 2.1 and need to define an Inflector rule for the word "Software", because CakePHP is converting all references to the plural form "Softwares" which isn't correct. Cake is looking for SoftwaresController and a table named Softwares.

I do know to create the rule in the boot strap, and read this doc reference.

http://book.cakephp.org/2.0/en/development/configuration.html#inflection-configuration

I also took a look at the lib/Cake/Inflector.php file, but can't figure out the syntax for defining a rule. It looks kind of like regex. Here are a few rule examples.

        '/(s)tatus$/i' => '\1\2tatuses',
        '/(quiz)$/i' => '\1zes',
        '/^(ox)$/i' => '\1\2en',
        '/([m|l])ouse$/i' => '\1ice',
        '/(matr|vert|ind)(ix|ex)$/i' => '\1ices',
        '/(x|ch|ss|sh)$/i' => '\1es',

What would be the correct code to define a Software singular Inflector rule?

EDIT:

 Inflector::rules('singular', array('rules'=>array('/software/'=>'software'),'irregular'=>array('software'=>'software'),'uninflected'=>array('software')));

I tried adding this rule, which works for the SoftwareController but Cake is complaining that it can't find the Softwares table, which is actually named "Software". I feel I'm close, but still missing something about how this works.

Reactgular
  • 52,335
  • 19
  • 158
  • 208
  • if that is the case it stands to question if a ticket should be opened for it here: http://www.cakephp.lighthouseapp.com/projects/42648/tickets/ - as Software never can be plural and `Softwares` therefore would be an incorrect inflector result and therefore a bug. – mark Mar 31 '12 at 19:57
  • True, but maybe the ticket should rather be for Cake to better document how to create Inflector rules of your own. I'll add one once I figure it out. – Reactgular Mar 31 '12 at 20:00

1 Answers1

8

you just have to know where to look (or search) in the book: http://book.cakephp.org/2.0/en/development/configuration.html#inflection-configuration

in your case

Inflector::rules('singular', array(
    'uninflected' => array('software')
));
Inflector::rules('plural', array(
    'uninflected' => array('software')
));
mark
  • 21,691
  • 3
  • 49
  • 71