以编程方式更新 Drupal CCK 字段

发布于 2024-11-28 03:17:44 字数 315 浏览 1 评论 0原文

如何以编程方式更新 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飘然心甜 2024-12-05 03:17:44

您应该能够将其放入您的预保存中,并正确保存它。我不能 100% 确定城市、纬度和经度是正确的键,但既然你有了它们,我就离开它们。

$node->field_location[0][city]      = 'tracker city';
$node->field_location[0][latitude]  = 8.888888;
$node->field_location[0][longitude] = 8.999999;

如果这不起作用,您应该安装 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.

$node->field_location[0][city]      = 'tracker city';
$node->field_location[0][latitude]  = 8.888888;
$node->field_location[0][longitude] = 8.999999;

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.

ま昔日黯然 2024-12-05 03:17:44
<?php
$node->language = LANGUAGE_NONE;
$node->field_custom_name[$node->language][0]['value'] = 'This is a custom field value';
?>

请参阅此处 了解更多信息。

<?php
$node->language = LANGUAGE_NONE;
$node->field_custom_name[$node->language][0]['value'] = 'This is a custom field value';
?>

See here for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文