【问题标题】:Drupal Hook_Menu access wildcardDrupal Hook_Menu 访问通配符
【发布时间】:2013-04-03 15:44:34
【问题描述】:

我想得到我的通配符,但我不能......

我在 Hook_menu 中的链接:

$items = array();


$items['tv8/channel/%'] = array(
    'title' => 'Detail channel Tv8',
    'description' => 'Détails d\'une chaîne Tv8',
    'page callback' => 'tv8_program_channel_detail',
    'access arguments' => array('access content'),
    'page arguments' => array(1),
    'type' => MENU_NORMAL_ITEM,
);

return $items;

我的链接是这样定义的:

"<a href='?q=tv8/channel/test'>" . $channel->name ."</a>" ,

这里是我的回调函数:

   function tv8_program_channel_detail($id)
{
    $content_admin_panel = $id.
                            "<div class='body'>" .
                                "<ul class='admin-list'>" .
                                    "<li>" .

                                        "<div class='description'>" .

                                        "</div>" .
                                    "</li>" .
                                    "<li>" .

                                        "<div class='description'>" .

                                        "</div>" .
                                    "</li>" .
                                "</ul>" .
                            "</div>";

    $content = array
    (
        'content' => array
        (
            '#markup' => t($content_admin_panel),
            '#prefix' => '<div class="admin-panel">',
            '#suffix' => '</div>',
        ),
    );

    return $content;
}

但 id 返回“频道”而不是“测试”。

我认为我做错了,但在 drupal 文档中找不到任何内容。

【问题讨论】:

标签: drupal menu hook


【解决方案1】:

在页面参数中,您需要将其更改为 array(2)。根据您的路径数组(0)加载“tv8”,数组(1)加载“频道”和数组(2)加载参数%。所以代码如下:

$items['tv8/channel/%'] = array(
    'title' => 'Detail channel Tv8',
    'description' => 'Détails d\'une chaîne Tv8',
    'page callback' => 'tv8_program_channel_detail',
    'access arguments' => array('access content'),
    'page arguments' => array(2),
    'type' => MENU_NORMAL_ITEM,
);

也更适合链接使用 php 函数 l():

<?php print l($channel->name, 'tv8/channel/test'); ?>

【讨论】:

    【解决方案2】:

    试试这个:

    $items['tv8/channel/%'] = array(
        'title' => 'Detail channel Tv8',
        'description' => 'Détails d\'une chaîne Tv8',
        'page callback' => 'tv8_program_channel_detail',
        'load arguments' => array(2),
        'access arguments' => array('access content'),
        'page arguments' => array(1),
        'type' => MENU_NORMAL_ITEM,
    );
    

    【讨论】:

      猜你喜欢
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      相关资源
      最近更新 更多