在drupal 7中基于id删除节点

时间:2017-08-09 11:07:41

标签: drupal-7 nodes

在我的drupal程序的这一部分中,我使用页面回调函数在页面上显示了节点。现在我需要做的是根据他们的ID删除节点。

我希望通过在每个显示节点的一侧提供“删除”链接来实现此目的。谁能帮我这个? 我对Drupal很新。所以详细的答案将不胜感激。 提前谢谢。

function mfrp_nodelist() {
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article') //this part also confused me, is it bundle, type or both? bundle works for me
->propertyCondition('status', 1)
->propertyCondition('uid', '1');
$result = $query->execute();
$nids = array_keys($result['node']);
$nodes = node_load_multiple($nids);
$output = node_view_multiple($nodes);
return $output;
}

3 个答案:

答案 0 :(得分:0)

PHP中通过节点ID删除节点的快速示例。

   $nid= 22; // $node id , which needs to be retrieved from delete link but hardcoded for now;
   node_delete($nid);

您需要创建一个类似这样的删除链接:

http://mydomain/nodes/delete?nid_delete=22

然后在PHP中,您可以通过PHP超级全局filter_xss($_GET['nid_delete]);

获取该值

答案 1 :(得分:0)

如果您有视图模块,您可以添加页面(将它们显示为网格或表格)并列出文章内容(添加标题,您需要的字段和删除链接)。通过使用删除链接,您可以删除节点(确保用户有权删除节点内容类型)

答案 2 :(得分:0)

我做了一些研究,发现了一种以列表形式显示节点的方法。并且还创建了删除链接。但是,我无法理解如何使链接工作。哪个页面连接链接以及如何在链接的基础上最终删除节点?任何帮助将不胜感激。

function mfrp_nodelist() {
$output = array();
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article') //this part also confused me, is it 
bundle, type or both? bundle works for me
->propertyCondition('status', 1)
->propertyCondition('uid', '1');
$result = $query->execute();
$nids = (array_keys($result['node']));
$nodes = node_load_multiple($nids);

$nid=array();
foreach ($nodes as $nid){
$outputs[] = array('data' => array( $nid->nid, $nid->title, "<a 
href='delete/{$nid->nid}'>" . t('Delete') . "</a>"."|"."<a href='edit/{$nid-
>nid}'>" . t('Edit') . "</a>"));
}
dpm($output);
echo "The number of records are ".count($outputs); 

$per_page = 4;
// Initialize the pager
$current_page = pager_default_initialize(count($outputs), $per_page);
// Split your list into page sized chunks
$chunks = array_chunk($outputs, $per_page, TRUE);
// Show the appropriate items from the list
$header = array(t('nid'),t('title'));

$output = theme('table',
array('header' => $header,
'rows' => $chunks[$current_page],
'attributes' => array(),
'empty' => t("No records found")));
// Show the pager
$output .= theme('pager', array('quantity',count($outputs)));
//return $output .= theme('pager',array('quantity',count($rows)));
return theme('mfrp_list', array('results' => $output));
}