0
我创建了一个带有数据库字段“tag
”,“tag_url
”和“tag_weight
”的小模块并填写它们。Drupal - 打印数据库输出到自定义块
现在我要输出的DB值在自定义模块,但我不知道如何创建它的正确方法: -/
/**
* Implements hook_block_info().
*
* This hook declares what blocks are provided by the module.
*/
function myModule_block_info() {
$blocks['example_uppercase'] = array(
// info: The name of the block.
'info' => t('Example: uppercase this please'),
'status' => TRUE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*
* This hook generates the contents of the blocks themselves.
*/
function myModule_block_view($delta = '') {
//The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'example_uppercase':
//Select items from DB
$result = db_select('myModule','ht')
->fields('ht',array('tag','tag_url','tag_weight'))
->execute();
**$block['content'] = foreach($result as $value) { echo $value->tag; }**
break;
}
return $block;
}
当我试图做到这一点,我得到:
PHP Parse error: syntax error, unexpected T_FOREACH in /.module on line 49
如何将数据库值打印到块?