drdzpknk76046
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?

图片转代码服务由CSDN问答提供 功能建议

我正在编写一个Drupal 7模块,用于查询我的数据库并打印出一个view_block,其中列出了属于 当前登录的用户:

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

此时,我需要用户选择他的一个项目进行可视化。

编辑:

我需要做的是在我的模块中调用另一个函数并将其传递给当前用户选择的项目的ID。

我知道如何添加链接 到表中的每一行并将ID值带到下一页,使用GET ['id']来检索它,但出于安全原因我真的不想更改url - 即我不知道 希望用户更改网址中的ID并查看其他人的项目,也不要阻止其发生。 我更喜欢尽可能保持网址清洁。

Drupal 7中的正确逻辑允许用户选择一个项目,然后调用模块中的另一个函数来加载数据。 选定的ID?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duannai5858
    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.

    点赞 评论

相关推荐