作为一般规则,不要为您的表使用名称,导致模型类名等于现有类名, Folder
例如是一个实用程序使用CakePHP进行类运输,这将导致您遇到自动加载问题。
这是一个应该/将被CakePHP 3修复的问题,其中命名空间正在使用。
...和单数
档案
变成 archife
听起来像是一个错误/冲突,请尝试
debug(Inflector :: singularize('archives'));
它对我使用CakePHP 2.5.1很好,即它返回 archive
,因此我建议您升级您的CakePHP版本,并报告为一个错误,以防它发生在最近的版本。
I'm having some weird behaviour from the cake console and I can't figure out what could possibly be wrong!
I've used the cake bake console before and not had any problems so hopefully it's not something glaringly stupid.
I have the tables: users, images and folders.
Folders and images both have user_id's
When I run the cake bake all on the folders table it bakes the controller and model but there's errors baking the views. I figured perhaps you can't call a table folders because of conventions or whatever so I renamed it 'archives'.
Now when I run the console and cd to myApp/app and cake bake all I get the model:1 archife2..
archife??
My table is most definitely called archives. I've changed the name a bunch of times to other names to check and it only seems to be on the particular word archives which it turns into archife. I've checked other words with 'v' in it but they're fine.
So.. my questions are twofold. Can we not use the table name folders because there's some problem with it? It's the only name I've come across apart from pages which you can't use as a table name because it clashes.
And, why does cake bake the table archives to the model archife?
Model names should be unique...
As a general rule, don't use names for your tables that would result in a model class name that equals an existing class name, Folder
for example is a utility class shipping with CakePHP, and this will cause problems with autoloading as you've experienced.
This is a problem that should/will be fixed with CakePHP 3, where namespaces are being used.
...and singulararchives
being turned into archife
sounds like it could be an Inflector
bug/conflict, try
debug(Inflector::singularize('archives'));
It's working fine for me using CakePHP 2.5.1, ie it returns archive
as expected, so I'd suggest to upgrade your CakePHP version, and report it as a bug in case it's happening with a recent version.
这篇关于cakephp - 命名表和使用蛋糕烘烤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!