Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP has the wrong model name

Tags:

php

model

cakephp

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

like image 568
Alex Avatar asked Mar 27 '11 22:03

Alex


1 Answers

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')));
like image 133
Robert Groves Avatar answered Oct 02 '22 19:10

Robert Groves