7
votes

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

class 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

2
What version of CakePHP are you using?Robert Groves
Oh sorry, I forgot. It's 1.3.8.Alex
It looks like your Taches fell victim of some kind of automatic depluralization. Though I don't know CakePHP..Imi Borbas

2 Answers

11
votes

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:

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')));
0
votes

You can set $uses with the model name in the TachesController:

class TachesController extends AppController {

    var $uses = 'Tache';