By Noktha on
I have a piece of code lifted out from Pro Drupal Development 2E, which originally came from user module.
$items['user'/%user_uid_optional'] = array(
'title' => 'My account',
'title callback' => 'user_page_title',
'title arguments' => array(1),
'page callback' => 'user_view',
'page arguments' => array(1),
'access callback' => 'user_view_access',
'access arguments' => array(1),
'file' => 'user_pages.inc',
);
I could not figure out what all the various array(1) in the code is for. Could anyone enlighten me on this?
Comments
% are placeholders...
The
array( 1 )bits refer back to the URL in question. It's a zero-indexed reference to the parts of the URL in$items. In this case,array( 1 )refers to the second part of the URL or%user_uid_optional.I don't think I'm making much sense... Perhaps an example?
For example going to
http://example.com/node/zero/one/two/threewith a hook_menu includingWould result in
I agree, it's not well documented. And judging my how poorly I just explained it, perhaps I can see why!
Hope that helps.
Mike Keran
www.MikeKeran.com
- Mike
Minor Corrections
Thank you for your post. However, I would like to point out just a slight mistake.
After running the code above, the output should be
instead of
since we have set
'page arguments' => array( 0, 1, 2, 3 )in the example above.I see parallels of this with command line arguments in Linux C programming (an example can be seen at http://www.physics.drexel.edu/students/courses/Comp_Phys/General/C_basic...), with the executable name replaced with the module name and using "/" as delimiters instead of the normal space in Linux. This small trivia may be useful for those of us with C programming background trying to work with Drupal.
Further more, it *is* possible to do funky stuff like
'page arguments' => array(1,2,1,2)and end up withbut we just need to remember to clear the cache before testing it out.
You're right
You're absolutely correct. That'll teach me to code in a comment!
Thanks for the correction -- I'd hate to leave misinformation for others to trip over.
Mike Keran
www.MikeKeran.com
- Mike