dsk49208 2011-10-05 21:19
浏览 25
已采纳

如何获取cck自定义字段的值和设置值

I know it might be a silly question to ask, but I have a field say a and b, now how to get the value and set the value for a and b. Right now my code is like this..

$n = node_load($node->id);
$n->title;

I am getting the node title, I want to know how to get and set the value for a and b please, and if i set the value of a and b will itt be saved using

node_save($n);

??

  • 写回答

2条回答 默认 最新

  • dongzhuonao8429 2011-10-05 22:40
    关注

    It depends a bit which version you're using and on the particular field types you're using, but something like this:

    // Drupal 6
    $n = node_load($node->id);
    $n->title = 'A title';
    $n->field_my_field_a[0]['value'] = 'A value';
    $n->field_my_field_b[0]['value'] = 'B value';
    node_save($n);
    
    // Drupal 7
    $n = node_load($node->id);
    $n->title = 'A title';
    $n->field_my_field_a[LANGUAGE_NONE][0]['value'] = 'A value';
    $n->field_my_field_b[LANGUAGE_NONE][0]['value'] = 'B value';
    node_save($n);
    

    In both cases the field data will be saved along with the node when you call node_save().

    It's worth noting that the 0 index in both cases refers to the first item in a field. If a field has multiple values you can just keep adding to the array. The value key might need to change depending on the type of data that the field holds (for example a filefield will hold the fid (file id) of the file it holds so adjust accordingly.

    Also LANGUAGE_NONE might need to be replaced by the required language code if you're using the Drupal 7 version.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路