<![CDATA[ function get() on null - MODX Community Forums]]> https://forums.modx.com/thread/?thread=104558 <![CDATA[function get() on null]]> https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562378
I get this error in my snippet:

MODx Revo 2.6.5
PHP 7

Fatal error: Uncaught Error: Call to a member function get() on null in /core/cache/includes/elements/modsnippet/186.include.cache.php:21 Stack trace: #0 /core/model/modx/modscript.class.php(70): include() #1 /core/model/modx/modparser.class.php(536): modScript->process(NULL) #2 /core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag(Array, true) #3 /core/model/modx/modparser.class.php(250): pdoParser->processTag(Array, true) #4 /core/components/pdotools/model/pdotools/pdoparser.class.php(65): modParser->processElementTags('', '<!doctype html>...', true, false, '[[', ']]', Array, 9) #5 /core/model/modx/modresponse.class.php(69): pdoParser->processElementTags('', '<!doctype html>...', true, false, '[[', ']]', Array, 10) #6 /core/model/modx/modrequ in /core/cache/includes/elements/modsnippet/186.include.cache.php on line 21


MyFF Snippet:

<?php
/*


$tv = Name der Template Variablen
$id = ID der Ressource

Beispiel: [[!myFF? &tv=`pagetitle` &id=`27`]]
*/

//------------ Template Variable einer bestimmten Ressource-ID ausgeben ---------------------//
   $parent = $modx->getObject('modResource', $id);

    //Der Aufruf zwischen den RessourceFields und den vom User angelegten TV's unterscheidet sich durch "get" und "getTVValue", deswegen if else...//
    
    if  ($tv == "pagetitle" or $tv == "longtitle" or $tv == "description" or $tv == "alias" or $tv == "link_attributes" or $tv == "published" or $tv == "pub_date" or $tv == "unpub_date" or $tv == "parent" or
        $tv == "isfolder" or $tv == "introtext" or $tv == "content" or $tv == "richtext" or $tv == "template" or $tv == "menuindex" or $tv == "searchable" or $tv == "cacheable" or $tv == "createdby" or
        $tv == "createdon" or $tv == "editedby" or $tv == "editedon" or $tv == "deleted" or $tv == "deletedon" or $tv == "deletedby" or $tv == "publishedon" or $tv == "publishedby" or $tv == "menutitle" or
        $tv == "donthit" or $tv == "privateweb" or $tv == "privatemgr" or $tv == "content_dispo" or $tv == "hidemenu" or $tv == "class_key" or $tv == "context_key" or $tv == "content_type" or $tv == "uri" or
        $tv == "uri_override" or $tv == "hide_children_in_tree" or $tv == "show_in_tree" or $tv == "properties")
        {return $parent->get($tv);}
    else if ($tv == null) {return "Keine Werte gefunden!";}  
    
    else {
        if ($parent->getTVValue($tv) != null) {return $parent->getTVValue($tv);}
        else {return "TV nicht gefunden oder enthält keine Werte!";}
    }



Please help, i dont understand what's wrong with get()?]]>
joe-petts Oct 29, 2018, 08:21 AM https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562378
<![CDATA[Re: function get() on null]]> https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562433
]]>
BobRay Oct 30, 2018, 08:35 PM https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562433
<![CDATA[Re: function get() on null]]> https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562427 ]]> joe-petts Oct 30, 2018, 03:30 PM https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562427 <![CDATA[Re: function get() on null (Best Answer)]]> https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562389
You can avoid it by wrapping the rest of the code in

if ($parent) {
    /* Your code here */
} else {
   /* Resource is at root of tree -- do something else or do nothing*/
}


]]>
BobRay Oct 29, 2018, 10:33 PM https://forums.modx.com/thread/104558/function-get-on-null#dis-post-562389