I have a view using arguments and a custom php field (I'm using views 2)
It seems when I place arg(1) into the IF statement it breaks it and prevents it from setting the variable?
I'm using this code:

<?php
if (arg(1) == 'term') {
$catid == '1101';
}
print $catid;
?>

yet it prints nothing???
I assume the variable is not being set
and when I print arg(1) it prints "term" (so now I at least know it has access to the argument)
And if I say:
$catid == '1101';
print $catid;
it prints 1101
Where am I messing up? Why won't the variable get set as 1101 within the if statement?
Thank you for any help you are able to provide!

Comments

nevets’s picture

If that is a views argument PHP code it needs to return $catid (not print it). If you want to check for debugging purposes you can used drupal_set_message("The id is $catid");

kmartindale’s picture

I think your talking about the argument section "provide default argument" using php. the problem I'm having is happening in the fields section, the arguments are working fine. If your wondering what I'm trying to do, I need the tid of the taxonomy term in the argument so I can use it later in some code. Also if you really are talking about the fields section, I just tried "return" and it broke, but thank you for your help.

streever’s picture

I think the question could also be read as "How do I get the arguments in a php custom field" if that helps you answer it, Nevets--I assume it is possible to call the argument from a field, and I would think the code we have would do it, but no dice.

I provide free Drupal support on Thursdays: booking calendar coming soon.

kmartindale’s picture

$vcat == arg(1);
if ($vcat == flowers) {
$catid == '1268';
}
print 1;
print arg(1);
print 2;
print $vcat;
print 3;
print $catid;

when I use this code, the outcome just says:
"1flowers23"
when it should display:
"1flowers2flowers31268"

$vcat is not being set, are we not able to grab from the arg(1)?

kmartindale’s picture

I found out the "==" is only meant for comparing, while the "=" is for setting the variable.

<?php
$vcat = arg(1);
if ($vcat == flowers) {
$catid = '1268';
}
print 1;
print arg(1);
print 2;
print $vcat;
print 3;
print $catid;
?>

then it prints: 1flowers2flowers31268
success!