By logictude on
I've read through most of http://drupaldocs.com and the forums, trying to find an answer for this. I'm hoping I'm just missing and it's something simple.
Wrote a custom node module, widget.module. Users can create a "widget", no problem. Inside widget.module I'm trying to write a block hook that will show when that users page is displayed. I want to show the widgets for that particular user.
Question, within:
<?php
function widget_block($op = 'list', $delta = 0) {
global $user;
...
}
?>
I want to reference the user being displayed, i.e. user/666, so I can show their widgets. When I reference global $user I get the currently logged in user, as I would expect. How do I get access to uid = 666?
-andrew
Comments
You mean uid of the logged user?
If so, then that should work:
so for example:
:).
I Mean the UID for the User Page
If I'm looking at http://domain.com/user/666 I want to get the uid, in this case 666, from within the custom block I've written. When I reference $user->uid I get the uid for the person logged in, which isn't the uid I want.
Whenever I load http://domain.com/user/uid I want that uid to show up in my custom block.
I'm sorry I'm not making a whole lot of sense.
-andrew
Ok, so my other reply was off
First assuming your module is called widget normally the path would be something like http://domain.com/widget/666 or http://domain.com/widget/user/666 (i.e. the path normally would include the module name to avoid clashes with other modules.
So in the code that processes the URL I would set a global to reflect the uid requested. Then in the block code refer to that global (I think this would work since I think blocks are processed after the main content, if not you code reference the current url path and strip the uid off)
Note: a draw back to the global, unless you have the block resticted to show only for the proper path other pages will show the block with the last uid referenced.
Are you looking for node data or user data?
Not sure what you mean by "How do I get access to uid = 666?"
If you are looking for the list of nodes owned by the user you need do an sql query with a where clause that includes node.uid = 666 (or as code 'node = ' . $user->uid) Depending on the query this could be different.
The full query will depend on what you want to achieve.
As an example you might do something like (Note: this is untested code)
This all goes in the else case for the block
I'm Definitely Not Explaining this Well, But I'll try again.
nevets: This is the logic I've written, we're on the same page. Here's the problem.
$user->uidreturns the uid of the currently logged-in person. I want to run the query using the uid of the user whose page i'm viewing... user/666. I don't know how to get that uid though.(I'm uid = 1. When I look at user/666 the block shows my "widgets" when I want it to show 666's "widgets".)
You need to parse URL
Something like nevets said here: http://drupal.org/node/18388#comment-30785
In Drupal You can get original URL query using:
so something like this should work (assuming You use clean URIs):