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