The site that I'm designing right now has a user dashboard that they see when they login. That dashboard will be at

http://www.domain.com/dashboard

The dashboard is exposed through a module using the _menu callback. But I need each users dashboard to be viewed by other people. Initially I thought I would start all of my paths off with the username. So that it would be

http://www.domain.com/nathanpalmer/dashboard

But I can't see a way to do this with a _menu call back. Outside of drupal I could simply parse the path and pull the correct information that way. I don't want to has the dashboard be a node because none of the content is static (there is no title and body.) It's all dynamically created.

Any ideas? I guess on the _menu callback I could query the user database and add to my array an item for each user. But then how do I pass a username or user id variable into my callback function?

Any ideas?

Thanks,

Nathan

Comments

nevets’s picture

Besides switching the path order I would use user id. So the path would be http://www.domain.com/dashboard/{user_id} where {user_id} is a number. The callback would only be 'dashboard' and the callback function would expect an argument, something like

function dashboard_menu($may_cache) {
  $items = array();

  if ( $may_cache ) {
     $items[] = array('path' => 'dashboard',
      'callback' => 'dashboard_page',
      'access' => TRUE,
      'type' => MENU_CALLBACK);
  }
}

function dashboard_page($uid) {
  $account = user_load(array('uid' => $uid));
  if ( $account->uid ) {
    // Valid account do something
  }
}
nathanpalmer’s picture

Thanks for the reply. We discussed reversing the order but there are a lot of paths that will be related to each user so it made more sense to start out with the user. I've been playing around with this a little bit and it looks like I can split the url and create the menu item only when it's called and it's a valid user like this.

		$url_array = split("/", $_SERVER['REQUEST_URI']);
		
		if (in_array('dashboard', $url_array)) {
			$row = db_fetch_object(db_query("SELECT users.uid, users.name, role.name as role_name FROM users, role, users_roles WHERE users.uid = users_roles.uid AND users_roles.rid = role.rid AND users.name = '" . $url_array[1] . "'"));
			if ($row) {
				if ($row->role_name == "agent") {
					watchdog("dashboard", "Adding agent path " . $row->name . '/dashboard');
					
					$items[] = array(
						'path' => $row->name . '/dashboard',
						'title' => t('Agent Dashboard'),
						'description' => t('Agent Dashboard.'),
						'callback' => 'dashboard_agent',
						'type' => MENU_CALLBACK,
						'access' => TRUE,
						'callback arguments' => array('username' => $row->name, 'uid' => $row->uid));
				} else {				
					watchdog("dashboard", "Adding homeowner path " . $row->name . '/dashboard');
					
					$items[] = array(
						'path' => $row->name . '/dashboard',
						'title' => t('Homeowner Dashboard'),
						'description' => t('Homeowner Dashboard.'),
						'callback' => 'dashboard_homeowner',
						'type' => MENU_CALLBACK,
						'access' => TRUE,
						'callback arguments' => array('username' => $row->name, 'uid' => $row->uid));
				}
			}
		}