CakePHP的型号名称错误

Ale*_*lex 7 php cakephp model

我现在正在尝试使用CakePHP而且我无法让我的应用程序正常工作,因为CakePHP"认为"我的模型名称是'Tach',而实际上是'Tache'.

为什么这样 ?

我的控制器定义为:app/controllers/taches_controller.php

class TachesController extends AppController {

function index() {

    $allTaches = $this->Tache->find('all');

    $this->set('taches', $allTaches);

}
Run Code Online (Sandbox Code Playgroud)

}

这是我的模型:app/models/tache.php

class Tache extends AppModel {

var $useTable = 'taches';
Run Code Online (Sandbox Code Playgroud)

}

如果我在控制器中使用'Tache',我会收到错误:

        $allTaches = $this->Tache->find('all');
Run Code Online (Sandbox Code Playgroud)

但如果我使用'Tach',我就不会收到任何错误:

        $allTaches = $this->Tach->find('all');
Run Code Online (Sandbox Code Playgroud)

为什么我不能使用型号名称'Tache'?难道我做错了什么 ?顺便说一下,我在php 5.3上,我的CakePHP版本是1.3.8

谢谢 !

亚历克斯

Rob*_*ves 11

CakePHP的默认变形规则认为Taches是Tach的复数形式.

您需要使用Inflector类添加自定义变形.

请参阅以下内容:

回顾一下,您需要在app/config/bootstrap.php文件中添加以下内容:

Inflector::rules('plural', array('irregular' => array('tache' => 'taches')));
Run Code Online (Sandbox Code Playgroud)