在 drupal 6 中存储简单数据并与视图共享的最有效方法?
我有一个简单的表单,允许用户从选择菜单中选择一个选项,然后将其保存在数据库中。我需要存储全名,以便视图可以使用它。所以我的数据库中的表可能看起来像这样:
nid | uid | type
------------------
1 | 2 | 0
2 | 2 | 3
1 | 3 | 5
3 | 1 | 4
等等...我正在考虑做一个基本的一对多关系表,例如:
tid | name
----------
0 | random name 1
1 | random name 2
2 | random name 3
3 | random name 4
但我最多只有 6-7 种类型,所以我不确定是否这是有效率的。在这种情况下,也许简单地存储全名而不是 ID 会更好?另一种方法可能是使用variable_get,但是我还需要允许在视图中使用php代码的自定义字段模块。在 drupal 中还有更好的方法吗?谢谢。
I have a simple form that allows users to select an option from a select menu and then save it in the database. I need to store the full name so that views can use it. So the table in my database might look like this:
nid | uid | type
------------------
1 | 2 | 0
2 | 2 | 3
1 | 3 | 5
3 | 1 | 4
and so on... I was thinking of doing a basic one to many relationship table like:
tid | name
----------
0 | random name 1
1 | random name 2
2 | random name 3
3 | random name 4
but I only have 6-7 types at the most, so I'm not sure if that is efficient. Maybe simply storing the full name instead of an ID would be better in that case? Another way might be to use variable_get, but then I also need the custom field module that allows php code in views. Any better way to do it in drupal? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将通过将术语放入分类法中并在 CCK 节点类型中使用该分类法来实现此目的。通过清除正文标签来关闭正文字段,并使用 auto nodetitle 关闭标题字段。这使得该类型的节点添加表单只是分类术语的选择列表,并且所有保存的节点都将公开给视图并可按用户和/或术语进行过滤。
这将为您提供一个与您所描述的非常相似的数据库,但会带来一些您永远不会注意到的额外开销,因为 Drupal 会缓存所有内容。
I would do this by putting the terms in a taxonomy and using that taxonomy in a CCK node type. Turn off the body field by clearing the body label and turn off the title field with auto nodetitle. That leaves your node add form for that type as just a select list of the taxonomy terms, and all saved nodes are exposed to views and filterable by user and/or term.
That'll give you a database that looks a lot like what you described, with an extra bit of overhead that you'll never notice because Drupal caches everything.
更好,因为“一段时间后”需要更少的支持......而且我认为性能不会比保留在现场有太大差异。另外,您还可以节省内存,因为字符串仅存储在小表中,并且引用数字不需要那么多空间......
It's better, because require less supporting "after some time"... And perfomance i think will not so differrence, than keep it in field. Also you save memory, because stings store only in little table, and referencing numbers require not so much place...