Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.2
Component:
Views Data
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Sep 2011 at 09:28 UTC
Updated:
28 Sep 2011 at 22:41 UTC
Hi Guys,
I'm trying to get a nid passed through to the arguments of a view, I have a simple function (in template.php) to work out a nid based on the page url. This works great and I'm using it to change theme elements on some sections of the website. However I'm trying to pass the nid through to a view in order to filter content based on it.
Here's my function:
function GetAssociatedProject()
{
$tempnodes = db_query("SELECT nid FROM node WHERE lcase(title) = '".str_replace('-',' ',strtolower(arg(1)))."' AND type = 'project' AND node.status = 1 AND language = '".UI_lang()."'");
$tempnode = db_fetch_object($tempnodes);
$myTempNode = $tempnode->nid;
return $myTempNode;
}
Just hoping someone can help after a good few days of trawling drupal.org looking for advice.
Comments
Comment #1
dawehnerSo you try to execute a view to find a certain nid and use this further? I'm not 100% sure what you mean witht this sentences.
Please don't tell people the url of your site, because this code is not secure. Please read how to use the database api of drupal.
Comment #2
andrew_hoffi commentedThanks for the tips on the Database Api.
I thought I could call the function within the PHP default argument for the view (called without php tags):
This would pass the nid through to the view and allow me to filter other content as the nid should reference a OG node.
Comment #3
dawehnerSure you can do this in the php argument default settings.
So did you tried this out? If yes, what is your problem ;)
Comment #4
andrew_hoffi commentedYeah sure... it doesn't seem to think the function exists. I have called it from page.tpl.php and its working fine, but it doesn't work within the default php view argument
Fatal error: Call to undefined function GetAssociatedProject() in /public_html/sites/all/modules/views/plugins/views_plugin_argument_default_php.inc(48) : eval()'d code on line 1
Comment #5
dawehnerSure you should place this function in your module file, if it should be usable in views, not in the template.php
The template.php is loaded much later.
Comment #6
andrew_hoffi commentedJust want to give you a HUGE thank you... not a huge task in the end, but still needed the push in the right direction.
Comment #7
andrew_hoffi commentedJust wanted to check if there could be anything that would stop a function being accessed by a view? I have a custom module all working correctly as it can be used elsewhere, just not by the view.
Comment #8
dawehnerThere is from my perspective no reason as long you have placed it in the .module file.