Page 1 of 1

Help With Error

Posted: Fri Sep 13, 2013 1:16 pm
by vipernet
Good day all,

When I add the following code to a template I'm getting an error:

Code: Select all

Strict Standards: Only variables should be assigned by reference in /home/content/10/11717410/html/lib/classes/class.usertagoperations.inc.php(265) : eval()'d code on line 8

Fatal error: Call to a member function getContent() on a non-object in /home/content/10/11717410/html/lib/classes/class.usertagoperations.inc.php(265) : eval()'d code on line 11
The code is :
{global_content name='side_nav'}
side_nav =

Code: Select all

<div id="side_nav">{build_side_nav}</div>
forgot the opt Script:
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

global $gCms;

$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
$currentNode = &$manager->sureGetNodeByAlias($thisPage);

// Get the URL to create menu indicator
$currentURL = $currentNode->getContent()->GetURL();


if (trim($currentNode->getContent()->Name()) != "Products") {
$currentNode = &$currentNode->getParent()->getParent();
}

echo '<h2>';

if ($currentURL == $currentNode->getContent()->GetURL()) {
echo '<span class="active_product"><img src="images/cobra/red_arrow.jpg" />&nbsp;' . $currentNode->getContent()->Name() . '</span>';
} else {
echo '<a href="' . $currentNode->getContent()->GetURL() . '">' . $currentNode->getContent()->Name() . '</a>';
}

echo '</h2>';

// Get all children for the current node (Note: a node isnt a page.)
$sectionNodes = $currentNode->getChildren();

// build the list based on hierarchy of nodes (see "pages" within CMS Content)
if ($currentNode->hasChildren()) {

echo '<ul>';

foreach ($sectionNodes as $sectionNode) {
$pageNodes = $sectionNode->getChildren();

if ($pageNodes) {
foreach($pageNodes as $pageNode) {

// get the content object
$content = $pageNode->getContent();

echo '<li>';

// if it is the current page, add image indicator
if ($content->GetURL() == $currentURL) {
echo '<span class="active_product"><img src="images/cobra/red_arrow.jpg" />&nbsp;' . $content->Name() . '</span>';
} else {
echo '<a href="' .$content->GetURL() . '">' . $content->Name() . '</a>';
}

echo '</li>';
}
}
}

echo '</ul>';

}

Re: Help With Error

Posted: Fri Sep 13, 2013 2:00 pm
by velden
I don't know much about this but I believe the $gCms variable does not exist anymore in newer versions.

Use cmsms() instead

http://docs.cmsmadesimple.org/tags/user ... ting-a-udt

Re: Help With Error

Posted: Fri Sep 13, 2013 2:03 pm
by calguy1000
This is a problem with your PHP code... not a CMS issue. Google the error, it will tell you about it.

Re: Help With Error

Posted: Fri Sep 13, 2013 5:08 pm
by vipernet
Thank you both for your reply.

I had it working on version 1.6.7. Now I upgraded to 1.11.7 still getting errors.
I read the link you gave me velden. I changed the following:

Code: Select all

global $gCms;
to

Code: Select all

 $gCms = cmsms();
That worked great, well got ride of the error on line 4

Still getting fatal Error on :

Code: Select all

$currentURL = $currentNode->getContent()->GetURL();
If anyone see's whats wrong with that please let me know.

Thanks all,

Re: Help With Error

Posted: Fri Sep 13, 2013 7:18 pm
by Jo Morg
I believe the problem comes from this bit:

Code: Select all

$thisPage = $gCms->variables['page_name'];
on line 7 of your post. AFAIK direct access to the variables has been removed at some point in CMSMS development.
An easy way to get around that would be to call the UDT like this:

Code: Select all

<div id="side_nav">{build_side_nav this_page=$page_alias}</div>
and then in the UDT use

Code: Select all

$thisPage = $params['this_page'];
to replace the previous line 7...
Obviously you can optimize the code even more, there is an obvious line too many, but at least it should work.
HTH

ps: there is an obvious disclaimer - there may be other issues with the UDT that I may not be able to pin point atm....

Re: Help With Error

Posted: Sat Sep 14, 2013 1:27 am
by vipernet
I made those two changes:

UDT:

Code: Select all

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

$gCms = cmsms();

$manager =& $gCms->GetHierarchyManager();
// $thisPage = $gCms->variables['page_name'];
$thisPage =  $params['this_page'];
$currentNode = $manager->sureGetNodeByAlias($thisPage);

// Get the URL to create menu indicator
$currentURL = $currentNode->getContent()->GetURL();

Global Content Block to :

Code: Select all

<div id="products_side_nav">{build_side_nav_cobra this_page=$page_alias}</div>
When I add this to template:

Code: Select all

{global_content name='cobra_side_nav_products'}
This getting the error:
Fatal error: Call to a member function getContent() on a non-object in /home/content/10/11717410/html/lib/classes/class.usertagoperations.inc.php(265) : eval()'d code on line 12
Been at this for awhile now. think I need to walk away and take look again, prob something stupid lol.

Re: Help With Error

Posted: Wed Sep 25, 2013 6:44 pm
by Dr.CSS
Can I ask what you expect this code to do..?