Administration menu
https://www.drupal.org/project/admin_menu
Writing module .info files
https://www.drupal.org/node/542202
function hook_block_info
https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_info/7
simplexml_load_file
http://php.net/manual/en/function.simplexml-load-file.php
---------------------- xml_importer.info ------------------------------
name = XML Importer
description = Import XML file
core = 7.x
package = XML_Importer
------------------- xml_importer.module -------------------------------
<?php
function xml_importer_block_info() {
$blocks['xml_view'] = array(
'info' => t('xml_view'),
'cache' => DRUPAL_NO_CACHE,
'region' => 'content',
'visibility' => BLOCK_VISIBILITY_PHP
);
return $blocks;
}
function xml_importer_block_view($delta = '') {
// This example is adapted from node.module.
$block = array();
if($delta == 'xml_view'){
$path = $_SERVER['DOCUMENT_ROOT']."/drupal-xml/sites/all/modules/xml_importer/books.xml";
$xml=simplexml_load_file($path) or die("Error: Cannot create object");
$items = array();
foreach($xml->children() as $books) {
$items[] = array(
'data' => 'Title - '.$books->title .'<BR/>'. 'Author - ' .$books->author .'<BR/>'. 'Genre - ' .$books->genre,
);
}
$block['content'] = theme('item_list', array('items' => $items));
}
return $block;
}
No comments:
Post a Comment