0

我创建了一个带有 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

如何将数据库值打印到块中?

4

1 回答 1

0

我发现我需要这样做:

https://drupal.org/node/1104498

于 2013-08-07T09:25:02.143 回答