以编程方式更新 Drupal CCK 字段
如何以编程方式更新 cck 字段?
我正在尝试以下代码,但没有成功:
$node->location[field_location][0][city] = 'tracker city';
$node->location[field_location][0][latitude] = 8.888888;
$node->location[field_location][0][longitude] = 9.999999;
我知道我可以直接与数据库交互,但我正在寻找不同的解决方案。
How can I update a cck field programmatically?
I am trying the following code, without any success:
$node->location[field_location][0][city] = 'tracker city';
$node->location[field_location][0][latitude] = 8.888888;
$node->location[field_location][0][longitude] = 9.999999;
I am aware I could directly interact with the database but I am looking for a different solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够将其放入您的预保存中,并正确保存它。我不能 100% 确定城市、纬度和经度是正确的键,但既然你有了它们,我就离开它们。
如果这不起作用,您应该安装 Devel 模块并使用 Node“Devel”选项卡查看节点对象并准确查看正确的格式是什么。
You should be able to put this in your presave, and have it save properly. I'm not 100% sure that city, latitude, and longitude are the correct keys, but I'm leaving them since you had them.
If that does not work, you should install the Devel module and use the Node 'Devel' tab to view the node object and see exactly what the proper format is.
请参阅此处 了解更多信息。
See here for more info.