Drupal 7 在drupal 7中基于id删除节点

Drupal 7 在drupal 7中基于id删除节点,drupal-7,nodes,Drupal 7,Nodes,在drupal程序的这一部分中,我使用页面回调函数在页面上显示了节点。现在我需要做的是根据节点的ID删除节点 我希望通过在每个显示的节点旁边提供一个“删除”链接来实现这一点。有人能帮我吗? 我对Drupal很陌生。因此,请提供详细的答复。 提前谢谢 function mfrp_nodelist() { $query = new EntityFieldQuery(); $result = $query ->entityCondition('entity_type', 'node') ->

在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;
}

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

   $nid= 22; // $node id , which needs to be retrieved from delete link but hardcoded for now;
   node_delete($nid);
您需要创建一个类似以下内容的删除链接:


然后在PHP中,您可以通过PHP超级全局过滤器获取该值

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

首先,您需要在drupal主题表中创建节点列表,此代码将用于在删除链接上进行剪辑

function yourmodule_rows() {
$rows = array()
$header = array(t('Sn no.'),t('Nid'),t('Node Title'),t('Op'),);
$query = db_select('node', 'n');
  $query->fields('n', array('title','nid'));
  $result = $query->execute();
  $sn = 0;
  while ($record = $result->fetchObject()) {
    $rows[] = array(++$sn, $record->nid, check_plain($record->title), l('Delete', 'node/'.$record->nid . '/delete'),);
}
  $render_array['yourmodule'] = array(array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('No Record found!'),), array('#theme' => 'pager',),);
  return $render_array;
}

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

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));
}

您能帮助我以列表的形式显示它们吗?$nids=array_keys$result['node'];。$nids是保存所有节点的节点ID的数组吗?如果是这样,为什么我不能使用foreach循环打印节点ID?为了根据您的解决方案创建链接,我需要单个节点ID。我如何获得这些信息?您能否共享查询结果?