We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51347
    • 82 Posts
    Hi all.

    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()?

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      The getObject() call on line 12 is failing. Usually, this is because the resource is at the root of the tree and has no parent.

      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*/
      }
      


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 51347
        • 82 Posts
        So easy! Thank you Bob. It works now smiley
          • 3749
          • 24,544 Posts
          I'm glad you got it sorted. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting