如何在drupal中查询cck字段?

时间:2010-12-03 07:19:55

标签: drupal cck

我有两个使用节点引用+节点引用url节点链接的内容类型(job_post和application)。当我单击job_post节点中的链接时,会创建一个新的应用程序节点,以便候选人可以填写他们的作业应用程序。我的目标是自动将cck电子邮件字段的内容从引用的job_post节点复制到应用程序节点中的cck电子邮件字段。

为实现这一目标,我创建了以下模块:

// Implementation of hook_perm()
      function mymodule_perm() {
 return array('copy cck field');
    }

 // Implementation of hook_node_api    

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4  = NULL){
 switch ($op) {

//if the node is inserted in the database

      case 'prepare':
        //if node is a job application
   if($node->type == 'application') {

//get nid from referenced node (using url information    
    $item_nid = arg(3);

//load and build node content
    $item_node = node_load($item_nid);
    $item_node = node_build_content($item_node);

//retrieve data from cck email field in referenced job post node    
                            $item_email = $item_node->field_job_email[0]['view'];

//display result in  website to check if value is correctly loaded
                            dsm($item_email);

不幸的是,当我收到此代码时,dsm返回并返回空值。

当我对代码进行以下更改时:

//retrieve data from cck email field in referenced job post node    
                            $item_email = $item_node->field_job_email;

//display result in  website to check if value is correctly loaded
                            dsm($item_email);

我在krumo得到以下结果:

... (Array, 1 element)
     0 (Array, 2 elements)
          email(string, 9 characters) aa@aa.com
          safe (string, 9 characters) aa@aa.com

有关如何将cck电子邮件地址字段(aa@aa.com)的内容加载到新字段的任何建议吗?

非常感谢你!

1 个答案:

答案 0 :(得分:0)

我可能在这里误解了一些内容,但Krumo似乎告诉你$item_node->field_job_email[0]没有“查看”属性。

您是否尝试过$item_email = $item_node->field_job_email[0]['safe'];