2010-12-03 101 views
2

我有两种使用节点引用+节点引用url节点链接的内容类型(job_post和application)。当我单击job_post节点中的链接时,会创建一个新的应用程序节点,以便候选人可以填写他们的工作应用程序。我的目标是自动将cck电子邮件字段的内容从引用的job_post节点复制到应用程序节点中的cck电子邮件字段。如何查询drupal中的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) [email protected] 
      safe (string, 9 characters) [email protected] 

如何加载CCK电子邮件地址字段的内容有任何建议([email protected])变成一个新的领域?

非常感谢!

回答

0

我可能会误解这里的某些内容,但Krumo似乎告诉你$item_node->field_job_email[0]没有“视图”属性。

你试过$item_email = $item_node->field_job_email[0]['safe'];

+0

这工作!非常感谢你的大力帮助(因为你发现我对PHP和Drupal还很陌生)。也适用于$ item_email = $ item_node-> field_job_email [0] ['email']; – user512826 2010-12-03 19:46:50