Hey people, I am having a really strange problem.
I have a view dispaying some fields (images). In the header of my view I included some php code using the php input format.
The code I put there is the following:
<?php
$view=views_get_current_view();
print_r($view->args);
print "name: ".$view->name;
print "url: ".$view->get_url();
?>
When I use the preview of the view with the argument 16, the view displays normally and the header containst the following:
Array ( [0] => 16 )
name: image_gallery
url: admin/build/views/nojs/preview/image_gallery/default/16
When I visit the view by the url of the page display though (for reference see http://kika.elcyon.nl/image_gallery/16), the view displays fine except for the header. The contents of the node is the same as in the preview of the view, the header is different though. It seems that the $view->args array is empty.
The header contains the following:
Array ( )
name: image_gallery
url: image_gallery
How this can be, I don't know, since the view displays the correct nodes/fields. The /16 in the url does get translated to an argument. But then it is somehow erased by the time the header is rendered. Neither the $view->get_url nor the $view->args contain the argument anymore. This really has me stumped.
This is my whole view, for reference:
$view = new view;
$view->name = 'image_gallery';
$view->description = 'Image gallery';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'image_files' => array(
'label' => 'Image files',
'required' => 0,
'image_size' => array(
'thumbnail' => 'thumbnail',
),
'id' => 'image_files',
'table' => 'node',
'field' => 'image_files',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'nid' => array(
'label' => '',
'link_to_node' => 1,
'which_node' => 'base_node',
'exclude' => 0,
'id' => 'nid',
'table' => 'image',
'field' => 'nid',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'term_node_tid_depth' => array(
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '%1',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'taxonomy_term',
'validate_fail' => 'not found',
'depth' => '5',
'break_phrase' => 1,
'set_breadcrumb' => 0,
'id' => 'term_node_tid_depth',
'table' => 'node',
'field' => 'term_node_tid_depth',
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'image' => 0,
'page' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'1' => 1,
),
'validate_argument_type' => 'tids',
'validate_argument_php' => '',
'image_size' => array(
'_original' => '_original',
'thumbnail' => 'thumbnail',
'preview' => 'preview',
),
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'image' => 'image',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('header', '<?php
$view=views_get_current_view();
print_r($view->args);
print "\\n";
print "name: ".$view->name;
print "\\n";
print "url: ".$view->get_url();
?>');
$handler->override_option('header_format', '3');
$handler->override_option('header_empty', 1);
$handler->override_option('footer', '<?php
$view=views_get_current_view();
print_r($view->args);
print "\\n";
print "name: ".$view->name;
?>
');
$handler->override_option('footer_format', '3');
$handler->override_option('footer_empty', 1);
$handler->override_option('items_per_page', 9);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
'columns' => '3',
'alignment' => 'vertical',
));
$handler->override_option('row_options', array(
'inline' => array(),
'separator' => '',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'image_gallery');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
Comments
Comment #1
merlinofchaos commentedHuh. I imported your view and I simply can't duplicate your problem.
Now, I don't have imagefield running here, so I switched it to just using node: title; so it's vaguely possible the problem is caused by imagefield (but I can't imagine it's doing anything to the args).
I will note one difference. On my successful run viewing the page view:
You got:
I got:
So I actually show the /1 as being part of the url. And I did have to manually go to image_gallery/1 since there is no direct linkage to it.
So, uh. I'm confused.
Comment #2
merlinofchaos commentedComment #3
petrovichby commentedI have the same problem. I'm trying to print argument in the Views Header using the code below, but result is always null.
At the same time, the argument is passing successfully, 'cause the content is filtered correctly.
Comment #4
summit commentedHi, Shouldn't args[0] be $argument with views2?
I am also struggeling with views argument phpcode.
greetings, Martijn
Comment #5
hefox commentedI'm also having this issue.
Looking at the views_set_current_view function my guessing is that it's not updating the view to the current view at some stage?
--
Edit: Nevermind, human error was the issue here
Comment #6
esmerel commentedNo updates in more than 30 days. This is not against the current version; if it's still a problem, open it back up with that.
Comment #7
jfox77 commentedI really struggled with this and had a hard time finding a solution. Finally, I put this in the "header" of my view. It doesn't show up in the preview but once I save it and go to the front end of my site it's there.
Comment #8
ice5nake commentedI am having the same or a very similar problem.
In the preview it displays "Message will go here" and the args. On the actual page it just displays "Message will go here".
I am using $view->render() to get display this view.
Comment #9
ice5nake commentedComment #10
ice5nake commentedComment #11
dawehnerCan you pastebin your full code you use to embed a view?
Comment #12
ice5nake commentedhttp://pastebin.com/Xge436BN
Comment #13
dawehnerneeds review means you have a patch.
You are missing $view->pre_execute();
Comment #14
ice5nake commented@dereine, thanks for your help . I replaced
$this->view->set_arguments(array($this->identifier));
with
$this->view->pre_execute(array($this->identifier));
Still isn't working. I also threw in a call to $this->view->post_execute() after $this->view->execute();
Comment #15
iamjon commentedhello all,
Can someone please update if they are still having issues with this. if yes please provide replication instructions using basic content types and fields and an export.
If you have found a solution please update so others may benefit.
i am assigning this to myself to keep better keep track of it.
Comment #16
dawehnerBased on #15
Comment #17
iamjon commentedI'm marking this as closed. Please feel free to reopen with more information.