1

I am using Views 2.16 on Drupal 6. I have the Content Profile module loaded and the profile has a nodereference field to another content type called Project. I would like to show a list of Projects in a block on the side when viewing the user page. I need to provide a default argument to a view since it is a block.

So the urls look like /user/admin, /user/joe who are related to content profile nodes 1867 and 1952 etc. I have the view showing correctly if I feed it a node id for a user profile as a hard coded value.

Now I want to do some stuff in the default argument code such as user_load(array('name' => arg(1)), content_profile_load($user->uid) and so on but it's not working.

What I have tried: print_r, var_export('abc', true), dpm($user), watchdog('php-test', 'a string').

None of these methods gave me any debug output. How can I debug the argument code?

2
  • Will you explain about ho your project nodes, Users (user objects) and Profile (Content profile nodes) combined ? Which node type has a node reference(or is it a user reference ?) tothe other node ? I have a answer in mind but not quite sure what your question is.
    – AKS
    Sep 7, 2012 at 22:05
  • Thanks for your comment. My question was only about how to debug the php code. I have reorganized my view and need a bit less code. The weird thing is watchdog statements seems to be working now but it seems to be delayed. The validation code may have been stopping anything from happening.
    – lolcode
    Sep 7, 2012 at 22:45

3 Answers 3

0

Rather than trying to debug the PHP code in the view, use the devel module's ability execute PHP code /devel/php to debug the bulk of your code before putting it in the Views PHP default argument field.

$arg = 1;  // admin or root user
$user = user_load(array('name' => $arg);
$profile = content_profile_load($user->uid);
var_dump($profile);

Then when you are ready you can drop the first linewhere we used the $arg variable for debugging and instead use arg(1)

$user = user_load(array('name' => arg(1));
4
  • If you have Devel, why not dsm() ?
    – AKS
    Sep 7, 2012 at 23:39
  • @AyeshK - Sure dsm() works well too. Just personal preference. I like a simple pain text representation, which I often save in a text file with other project assets for quick reference.
    – Rider_X
    Sep 8, 2012 at 1:28
  • This seems like a good suggestion that I was not aware of. I will look into it for debugging code.
    – lolcode
    Sep 9, 2012 at 0:43
  • Accepting this as it was the only one that addresses the question of how to debug and it was new to me.
    – lolcode
    Sep 9, 2012 at 0:44
0

After more testing it appears that the watchdog function does work for debugging the embedded PHP code in the Argument Validator and Argument Default Value. I believe my validation was too strict previously and was preventing any output. For example embedding the line below in the "PHP validate code: " area gives all the argument components.

watchdog('block-args-php', var_export(arg(), TRUE)); 
0

I think you are using a couple extra steps here.

If www.yourhost.com/users/joe is a content profile with nid 1952 its system path is indeed www.yourhost.com/node/1952. But you are ignoring the fact that it is also "owned" by user joe, and instead going through the user load to get his (I assume :) uid, all the while it's already in there much like this:

 $node=menu_get_object(); // returns everything about the current node (so this won't work in a Views preview :))

where $node->uid will contain the owner of the node you are looking at, which, if we are sitting on a content profile, is that user's uid.

Further, in Views 3 at least, I've not used Views 2 in a long while, you can use a user id as an argument, and for the default argument needed in your block, have Views grab it from the url/set it to the node author, so, you may be able to do all of this without any custom php.

1
  • 1
    Yes, after some more modifications to the view it finally worked with just "User ID from URL" as the default value. So, all the PHP work I did I will just chalk up to experience...lol.
    – lolcode
    Sep 9, 2012 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.