简体   繁体   English

cakePHP - 如何在控制器和不同模型的视图之间划分管理?

[英]cakePHP - how to divide managment between controllers and views of different models?

I have two models, lists and lists_items 我有两个模型, listslists_items
I have a basic crud structure for them. 我有一个基本的crud结构。
I've also set the hasMany (in lists ) and belongsTo (in lists_items ). 我还设置了hasMany (在lists )和belongsTo (在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. 我现在想要的是添加一个选项来在父列表的编辑视图中编辑list_items。

Please advice me how to create the proper MVC for that. 请告诉我如何为此创建适当的MVC。
(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) (我只是无法找出我应该使用'正确做'的正确元素/组件/等等,我可以简单地将一些MVC片段粘在一起它会起作用,但我有足够的经典asp)
;-) ;-)

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". 您的命名约定:“lists_items”通常用于HABTM关系,如果它是一个HABTM你需要把单词按字母顺序,如:“items_lists”。 If this is a standard belongsTo , you should name the table: "list_items". 如果这是标准的belongsTo ,则应该为表命名:“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. 您应该使用bake来熟悉CakePHP文件结构,并且可以在模型中研究关系代码。

Being able to edit related "parent" model data is usually not difficult if you are following convention and reading the manual about relationships. 如果您遵循惯例并阅读有关关系的手册,则能够编辑相关的“父”模型数据通常并不困难。

Keep in mind "doing it right" in CakePHP is following the convention that was laid out in the manual. 请记住,CakePHP中的“正确执行”遵循手册中列出的惯例。 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. 我知道并非手册中涵盖了所有内容和细节,因为它与一般的面向对象概念和一般编程概念(理解数组等)有很大关系。学习CakePHP不是一夜之间的过程,也是唯一的建议我可以做的是练习,练习,练习和阅读,阅读,阅读手册一遍又一遍:)祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM