Going crazy here.
I have struggled all morning to get a view working and it's not. For some crazy reason, I just decided to try a block, and it works great!
I am using php to provde the argument. Basically, I am pulling the nid from a node referrer field.. like this.
<?php
$node_id = arg(1);
$node = node_load($node_id);
return $node->field_node_reference_field[0]['nid'];
?>The page view and block view are identical. No changes. I had wanted to attach this view using views attach to a node, take the node id in the url and use it to get the node id of the referenced node, then pass that to views. When I saw that the block was working, I was going to report this as a bug in Views Attach, but then I tried a regular page view, added the arg(1) and it doesn't work BUT the block pops up with the correct view, containing the correct items.
THIS, THIS is why I did not get a degree in comp sci. What am I missing? Would greatly appreciate help.
Comments
Whats the path you are using
Whats the path you are using for the page view? How are you invoking it?
Note that for arguments, the default argument is only used "if argument is not present", so my guess is the page view is trying to get the argument from the path.
Breaking it down..
The page that I would like to attach the view to has this url.
www.mysite.com/?q=node/332
I have included this code in my contemplate to try and make sure that I am not going crazy.
<?php$node_id = arg(1);
print 'The node id is from url is' . " " . $node_id . '<br/>';
$node = node_load($node_id);
print 'The node id of the reference field is ' . $node->field_hp_patient[0]['nid'];
?>
The print in the node body for this code is..
The node id is from url is 332
The node id of the reference field is 100
I then create a view.
Type:node
Argument: Node: Nodereferrer: by node type. Provide default argument. PHP Code. (without the
<?php
?>
<?php$node_id = arg(1);
$node = node_load($node_id);
return $node->field_hp_patient[0]['nid'];
?>
Validator: basic
Action to take if argument does not validate :404
Operator : Return nodes that refer to given node id.
referring node type is selected.
Page Title: test
If I then view
www.mysite.com/?q=test/332 I get a blank page.. Interestingly, if I view www.mysite.com/?q=test/100 it works.
My query is as follows.
SELECT node.nid AS nid,
node_data_field_diagnsosis_icd_nine.field_diagnsosis_icd_nine_value AS node_data_field_diagnsosis_icd_nine_field_diagnsosis_icd_nine_value,
node.type AS node_type,
node.vid AS node_vid
FROM node node
LEFT JOIN content_type_diagnosis node_data_field_diagnsosis_icd_nine ON node.vid = node_data_field_diagnsosis_icd_nine.vid
WHERE FALSE
Really befuddled.
Whats the path for the page
Whats the path for the page view, i am guessing 'test', in which case 332, 100 or what ever comes after 'test' is the argument, note the PHP code is only used if not argument is present in the path.
Ahhh..hrm
Yes, test/336 is the path..
I'm confused. I use get node id from url all the time.. it's not the first argument.. node/ is.
So how can I can I do this then? Where would I get the nodeid from the url and slip in my code?
I guess, I'll run with this..
http://drupal.org/node/330959
This has some info on embedding views using contemplate. Instead of using views attach. I will just embed everything in contemplate and then pass arguments this way.
I'm sure I'll have more questions. Thanks a ton for your help. You saved me some hair.