cakephp - 命名表和使用蛋糕烘烤 [英] cakephp - naming tables and using cake bake

查看:113
本文介绍了cakephp - 命名表和使用蛋糕烘烤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从蛋糕控制台有一些奇怪的行为,我不知道什么可能是错误的!



我使用了蛋糕烘焙控制台



我有表格:用户,图片和文件夹。



文件夹和图片都有user_id的



当我运行的蛋糕烘烤所有的文件夹表,它烘烤控制器和模型,但有烘焙视图的错误。我想也许你不能调用表文件夹,因为约定或任何所以我重命名为档案。



现在当我运行控制台和cd到myApp / app and cake bake all我得到的模型:
1 archife
2 ..



archife ??



我的表是绝对称为档案。我改变了名字一次,其他名字检查,它只是似乎在特定的字存档,它变成archife。我已经检查其他单词与'v'在它,但他们很好。



所以..我的问题是双重的。我们不能使用表名文件夹,因为它有一些问题吗?这是我遇到的唯一的名字,除了你不能用作表名称的页面,因为它冲突。



而且,为什么蛋糕烘焙表档案> 模型名称应该是唯一的...

作为一般规则,不要为您的表使用名称,导致模型类名等于现有类名, Folder 例如是一个实用程序使用CakePHP进行类运输,这将导致您遇到自动加载问题。



这是一个应该/将被CakePHP 3修复的问题,其中命名空间正在使用。



...和单数



档案变成 archife 听起来像是一个 Inflector 错误/冲突,请尝试

  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 archife 2..

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 singular

archives 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 - 命名表和使用蛋糕烘烤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆