cakePHP - 如何在不同模型的控制器和视图之间划分管理?
我有两个模型,lists
和 lists_items
我有一个基本的粗略结构。
我还设置了 hasMany
(在 lists
中)和 belongsTo
(在 lists_items
中)。
我现在想要的是添加一个选项来在父列表的编辑视图中编辑 list_items 本身。
请建议我如何为此创建正确的 MVC。
(我只是不知道什么是正确的元素/组件/等等,我应该使用“正确执行”,我可以简单地将一些 MVC 片段粘合在一起,它会工作,但我已经受够了经典的 asp)< br> ;-)
I have two models, lists
and lists_items
I have a basic crud structure for them.
I've also set the hasMany
(in lists
) and belongsTo
(in lists_items
).
What I want now is to add an option to edit the list_items themselves in the edit view of the parent list.
Please advice me how to create the proper MVC for that.
(I just can't find out what are the correct element/components/etc that I should use 'to do it right', I can simply glue together some MVC pieces and it will work, but I had enough of classic asp)
;-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为我没有回答您的问题,因为我在您的设置中看到了其他问题(至少我认为存在)。
您的命名约定:“lists_items”通常用于 HABTM 关系,并且如果这是一个HABTM,您需要按字母顺序排列单词,例如:“items_lists” 。如果这是标准的 belongsTo,您应该将该表命名为:“list_items”。这只是按照惯例。
您可能应该使用bake 来熟悉CakePHP 文件结构,并且可以研究模型中的关系代码。
如果您遵循约定并阅读有关关系的手册,那么编辑相关的“父”模型数据通常并不困难。
I don't think I am answering your questions because there are other problems I see in your setup (at least I assume there is).
Your naming convention: "lists_items" is usually used for a HABTM relationship, and if it's a HABTM you need to put the words in alphabetical order like: "items_lists". If this is a standard belongsTo, you should name the table: "list_items". This is just per convention.
And you should probably use bake to get familiar with the CakePHP file structure and you can study the relationship code in the models.
Being able to edit related "parent" model data is usually not difficult if you are following convention and reading the manual about relationships.
请记住,CakePHP 中的“正确做法”是遵循手册中规定的约定。我知道手册中并没有涵盖所有的事情和细节,因为其中很多都与一般的面向对象概念和一般编程概念(理解数组等)有关。有效地学习 CakePHP 不是一朝一夕的过程,也是我唯一的建议可以做的是练习、练习、练习和阅读、阅读、一遍又一遍地阅读手册:)祝你好运。
Keep in mind "doing it right" in CakePHP is following the convention that was laid out in the manual. I know NOT every single thing and detail is covered in the manual as a lot of it has to do with general Object Oriented concepts and general programming concepts (understanding arrays etc).. Learning CakePHP effectively is not an overnight process and the only suggestion I can make is practice, practice, practice and read, read, read the manual over and over again :) Best luck.