Page 1 of 1

UDT errors - missing something [solved]

Posted: Sat Mar 14, 2009 7:05 am
by geepers
I've tried to get more involved UDT's working within a couple of CMSMS installations (v 1.5.2 & 1.5.3).

I've entered this sample code from another post for a UDT I named 'test':

Code: Select all

global $gCms;
$hm =& $gCms->GetHierarchyManager();
$curnode =& $hm->getNodeById($page_content_id);
$curcontent =& $curnode->GetContent();
echo 'Page URL: ' . $curcontent->GetURL();
When I attempt to include {test} on the default template, I get the following error:

Fatal error: Call to a member function on a non-object in /home/greg/x1.swdmedia.com/html/lib/content.functions.php(857) : eval()'d code on line 4

What could possibly be causing the issue?

I've searched through my error logs but there's nothing showing up there.

/g

Re: UDT errors - missing something

Posted: Mon Mar 16, 2009 2:52 pm
by plger
$page_content_id seems not to be defined, therefore getNodeById returns false, and (therefore) $curnode is not an object and does not have the GetContent() function, which trigger the error. Smarty variables are not available (not directly) in UDT.

Two things here :

1. To retrieve the page id, you could use $gCms->variables["page_id"], or else give it as an input to the tag : {test pageid=something} and retrieve it in the UDT using $params["pageid"]

2. You should always check that you successfully retrieved a node :

Code: Select all

if($curnode) {
$curcontent =& $curnode->GetContent();
echo 'Page URL: ' . $curcontent->GetURL();
}

Re: UDT errors - missing something

Posted: Tue Mar 31, 2009 10:36 pm
by geepers
Thanks plger - was unable to try your recommendations til now, but it helped me immensely.

CHEERS!