php - CakePHP 的型号名称错误

标签 php cakephp model

我现在正在试用 CakePHP,但我无法让我的应用程序正常工作,因为 CakePHP“认为”我的模型名称是“Tach”,而实际上它是“Tache”。

为什么会这样?

我的 Controller 定义为: 应用程序/ Controller /taches_controller.php

class TachesController extends AppController {

function index() {

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

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

}

这是我的模型: 应用程序/模型/tache.php

class Tache extends AppModel {

var $useTable = 'taches';

如果我在我的 Controller 中使用“Tache”,我会得到一个错误:

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

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

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

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

谢谢!

亚历克斯

最佳答案

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

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

请参阅以下内容:

回顾一下,您需要将如下内容添加到您的 app/config/bootstrap.php 文件中:

Inflector::rules('plural', array('irregular' => array('tache' => 'taches')));

关于php - CakePHP 的型号名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5453023/

相关文章:

PHP 邮件程序 - SMTP GMAIL 身份验证

php - php 未获取 javascript 值

php - CakePHP 3.X 中的自动完成小部件

cakephp - save() 返回 false,但 CakePHP 中没有错误

c# - ASP.NET MVC 中的模型警告

php - Joomla 模型类型之间有什么区别?

php - 从头开始构建快速语义私有(private)文章MySQL搜索引擎

php - mysql php 数据库将共享一个成员表但没有别的吗?

php - 访问cake php中的复合表数据

javascript - 如何从服务器保留空值? (Groovy 和 JavaScript)