UDT errors - missing something [solved]

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
geepers
Dev Team Member
Dev Team Member
Posts: 84
Joined: Thu Nov 22, 2007 10:41 pm
Location: Canada

UDT errors - missing something [solved]

Post 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
Last edited by geepers on Tue Mar 31, 2009 10:37 pm, edited 1 time in total.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: UDT errors - missing something

Post 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();
}
geepers
Dev Team Member
Dev Team Member
Posts: 84
Joined: Thu Nov 22, 2007 10:41 pm
Location: Canada

Re: UDT errors - missing something

Post by geepers »

Thanks plger - was unable to try your recommendations til now, but it helped me immensely.

CHEERS!
Post Reply

Return to “Developers Discussion”