douchuoxuan3177 2010-04-14 17:59
浏览 75
已采纳

自定义页面GET请求上的Drupal清理URL

I have a drupal page (content type page) that should accept GET values using clean urls.

I put the following code in the page body using the php code input format.

<?php
  $uid = $_GET['uid'];
  $user = user_load($uid);
  print $user->name;
?>

Now the following link http://www.example.com/mypath/?uid=5 results in user 5's name being displayed. Great.

My question is: Can this be accomplished using clean urls such that going to http://www.example.com/mypath/5 has the same result? (Similar to using arguments in views)

  • 写回答

3条回答 默认 最新

  • douchunji1885 2010-04-14 18:25
    关注

    You can do what you ask in the menu system using hook_menu in a module, but you can't create an alias where a part of it is a name. The whole alias is a name, so you can't extract info from it. Using hook_menu you can do this:

    function my_module_menu() {
      $items = array();
    
      $items['path/%user'] = array(
        'title' => 'Title',
        'page callback' => 'callback',
        'page arguments' => array(1),
        'access callback' => '...',
        'access arguments' => array(...),
      );
    
      return $items;
    }
    

    Then in your callback function you will have the value or argument 1 in the path which corresponds to the uid (in reality it will be a loaded user object because of %user).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄