Have a view set up to take an argument from user/%/linked-students. It worked during my first testings, then just stopped all the sudden, and I've finally figured out why.

Validation PHP code:

global $user;
return $argument[0] == $user->uid;

I was testing on the path user/14/linked-students, and started looking at the argument with drupal_set_message. Turns out that $argument[0] has a value of "1", which was odd, since it should have been "14". Thought it had something to do with the fact that I was logged in with my admin user too.

Anyhow, but then $argument[1] turns out to be "4". So it's looking like the $argument array is for some reason an array of each digit in the actual argument. This was why it was working when I started testing, since I was working with single-digit users.

Anyhow, no idea why this might be, but using arg(1) instead of $argument[0] seems to do the trick for now.

Not sure if it's important, but my user:uid argument was set up to use a node reference relationship. Not sure if this is universal with the $argument array, but it might lead to loads of wasted time for many, so I'm marking as critical :)

Cheers all!

Comments

dawehner’s picture

Status: Active » Fixed

Sure. You only validate a single argument here. So $argument is the string 14, and $argument[0] returns 1 :)

patcon’s picture

Ah.... Really?! Sorry about that! My bad
Just a quick followup Q: single arguments are always broken up into arrays of characters?

Thanks again yo

patcon’s picture

Anyhow, I tracked down the tutorial I found this on:
http://gotdrupal.com/comment/reply/40/205

I'm making a comment on the post to set him straight and save others some grief, but I'm not sure this feature is useful: Those who know drupal well enough to expect it can probably make it happen on their own fairly easily, and the rest of us just waste a bunch of time troubleshooting. It doesn't help that for nodes 10-19 that are tested, the admins think any validation they do is working fine, but then they discover it won't work for other users, and it confuses the hell out of them. Any thoughts?

Hopefully I don't come across as one of the people trying to bend drupal exclusively to their needs, but I'm just trying to make things more user friendly for others...!

merlinofchaos’s picture

Sorry, yes, that is PHP for you. If you have a string, then $string[0] is the first character of that string and $string[1] is the second.

Views 2 has never passed $argument as an array; in Views 1, all arguments came in an array and you had only 1 argument PHP code spot. So Views 2 works a little differently there. Maybe that's part of the problem.

BenK’s picture

Subscribing...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.