我创建了一个带有 DB 字段“ tag
”、“ tag_url
”和“ tag_weight
”的小模块以及填写它们的表格。
现在我想在自定义块中输出 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 错误:语法错误,第 49 行 /.module 中的意外 T_FOREACH
如何将数据库值打印到块中?