我现在正在试用 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 类来添加自定义变形。
请参阅以下内容:
第 3.4.6 Inflections的食谱。其中解释了自定义变形。
Inflector Class Info来自 API 文档。
回顾一下,您需要将如下内容添加到您的 app/config/bootstrap.php 文件中:
Inflector::rules('plural', array('irregular' => array('tache' => 'taches')));
关于php - CakePHP 的型号名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5453023/