文件夹名称:yourModule
在该文件夹中,我有两个文件..一个文件是" yourModule.info" ....另一个是" yourModule.module"。
yourModule.info代码:
;$ID$
name = "Your Module"
description = "Place to put PHP functions for Drupal customizations."
core = 7.x
yourModule.module代码:
/*****************************************************************************
* Implementation of hook_block()
* @see http://api.drupal.org/api/function/hook_block/6
* create a minimal block
*/
function yourModule_block( $op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
// appears on the Blocks configuration page admin/build/block<br>
$blocks = array();
$blocks[0]['info'] = t('My Block');
return $blocks;
case 'view':
// content of block; required to have 'subject' and 'content' elements
$blocks = array();
$blocks['subject'] = t('<center>My Block Status</center>');
$blocks['content'] = t('<center>My Block Content</center>');
return $blocks;
}
}
我正在搜索谷歌这个3天没有用..我正在使用drupal 7和wamp on windows-xp ...请救我
答案 0 :(得分:1)
您已将问题标记为Drupal 7,实际上您的模块的信息文件声明core = 7.x
,但您正在使用Drupal 6中的块挂钩。
对于Drupal 7,您需要分别使用hook_block_info()
和hook_block_view()
。
function yourModule_block_info() {
$blocks['my_block'] = array(
'info' => t('My Block'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
function yourModule_block_view($delta = '') {
$block = array();
if ($delta == 'my_block') {
$block['subject'] = t('My Block Status');
$block['content'] = t('My Block Content');
}
return $block;
}
答案 1 :(得分:0)
hook_block()。查看block.api.php以获取更多信息。