drdzpknk76046 2017-10-16 12:53
浏览 56
已采纳

如何从block_view调用模块中的函数

I am writing a Drupal 7 module that queries my db and prints out a view_block with a list of projects belonging to the current logged user:

ID ClientName ProjectName ProjectDescription
 1     mickey       toon1        bla bla bla
 2      mouse       toon2        bla bla bla

At this point, I need the user to select one of his projects to proceed to visualization.

EDIT:

what I need to do is to call another function in my module and pass it the ID for the project selected by the current user.

I know how to add a link to every row in the table and bring the ID value with me to the next page, using GET['id'] to retrieve it, but I really don't want to change the url for security reasons - namely, I don't want users to change the ID in the url and see other people's projects, nor prevent it to happen. I prefer to keep url clean as much as possible.

What is in Drupal 7 the right logic to allow the user select one project and then call another function in my module to load data according to the selected ID?

  • 写回答

1条回答 默认 最新

  • duannai5858 2017-10-17 08:55
    关注

    I would implement an hook_menu. With this solution you need to pass the Id of the project in the url, but an hook menu allow you to define 2 functions. The access function will check if the user has access to the project, the callback function will retrieve the project and show the project details.

    This is a simple example of how I would implement it:

    /**
     * Implements hook_menu().
     */
    function my_module_menu() {
        $items['my_module/show_project_detail/%'] = array(
            'title' => 'Show Task Detail',
            'access callback' => 'show_project_access',
            'access arguments' => array(1),
            'title callback' => false,
            'page callback' => 'show_project',
            'page arguments' => array(1),
        );
        return $items;
    }
    
    function show_project_access( $sProjectId ){
        // checks if the user has access to $sProjectId.
        // returns true if he has access, otherwise returns false
    }
    
    function show_project( $sProjectId ){
        //returns the html of the task's detail view
    }
    

    Then to call the hook_menu you will call this url https://my_drupal/my_module/show_project_detail/123 where 123 is the project Id.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了