CakePHP has the wrong model name
I'm trying out CakePHP now and I can't get my app working because CakePHP "thinks" my model name is 'Tach' when it's in fact 'Tache'.
Why so ?
My controller is defined as : app/controllers/taches_controller.php
cla开发者_JAVA技巧ss TachesController extends AppController {
function index() {
$allTaches = $this->Tache->find('all');
$this->set('taches', $allTaches);
}
}
And here's my model : app/models/tache.php
class Tache extends AppModel {
var $useTable = 'taches';
}
I get an error if I use 'Tache' in my controller :
$allTaches = $this->Tache->find('all');
But if I use 'Tach', I get no error :
$allTaches = $this->Tach->find('all');
Why can't I use the model name 'Tache' ? Am I doing something wrong ? By the way I'm on php 5.3 and my CakePHP version is 1.3.8
Thanks !
Alex
CakePHP's default inflection rules think that Taches is the plural form of Tach.
You'll need to use the Inflector class to add a custom inflection.
See the following:
Section 3.4.6 Inflections of the cookbook. Which explains about custom inflections.
Inflector Class Info from the API doc.
To recap you'll need to add something like the following to your app/config/bootstrap.php file:
Inflector::rules('plural', array('irregular' => array('tache' => 'taches')));
You can set $uses with the model name in the TachesController:
class TachesController extends AppController {
var $uses = 'Tache';
精彩评论