Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a singular rule in the bootstrap for Inflector

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.

like image 412
Reactgular Avatar asked Mar 31 '12 19:03

Reactgular


1 Answers

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')
));
like image 122
mark Avatar answered Sep 23 '22 12:09

mark