使用 Zend_Db 复制和更新
我有 4 张桌子。客户、模板、元素和 ElementsToTemplate。非常不言自明。客户可以有 n 个模板。模板可以有 n 个元素。一个模板可以有 1 个客户。一个元素可以有 1 个模板。
所以,现在我需要为模板和客户提供删除和复制功能。
最好的方法是什么?
Atm,我有一个,实际上没那么难看的怪物功能: http://pastebin.com/yBqKYnCC
我只是我想,我的设计有点糟糕,因为我为每个人都有一个模型/对象。客户、元素和模板。无论如何,它并没有那么难看,而且我是新手。这是我一开始没有想到的事情。
删除。对于删除,您可能已经注意到,我只是设置了一个标志,实际上并没有删除任何内容。是否有一些奇特的方法可以使用 Zend_Db_Select 在一个查询中更新所有内容?还是我必须像复制时一样检查所有这些?
谢谢
I have 4 Tables. Customers, Templates, Elements and ElementsToTemplate. Quite self-explanatory. Customer can have n Templates. Templates can have n Elements. A Template can have 1 customer. A element can have 1 template.
So, now i need to make a delete and copy functionality for templates and customer.
What's the best approach for that?
Atm, i have a, actually not that ugly, monster function: http://pastebin.com/yBqKYnCC
I just think, my Design sucks a bit since i have for each one a Model/Object. Customer, Element and Template. Anyway, it isn't that ugly and I'm a newbie. This is stuff i didn't think of in the beginning.
Deleting. For deleting, as you probably noticed, I just set a flag and don't actually deleted anything. Is there some fancy way to update all in one query with Zend_Db_Select? Or do i have to go through all of them like i did for the copying?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你的心在正确的地方。 :)
你的函数有点像一个怪物,它可能应该被分解为 3 或 4 个不同的函数。
为了保持简单而不是重新发明轮子,我建议您查看几个链接以了解使用 Zend_Db_Table 的更简单方法。
第一篇是非常好的 ZF 入门知识,它将为使用 Zend_Db_Table 奠定基础:
Rob Allen 的 ZF 1.11 教程
第二个更深入地探讨关系:
Mat M ZF 中的表关系
Ok your heart is in the right place. :)
Your function is kind of a monster, it should probably be broken down into 3 or 4 different functions.
To keep it simple and not reinvent the wheel I suggest you look at a couple of links to get the idea of the easier ways to use Zend_Db_Table.
The first is really good ZF primer that will lay the groundwork for using Zend_Db_Table:
Rob Allen's ZF 1.11 Tutorial
The second one goes deeper into relationships:
Mat M. Table Relationships in ZF