We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5904
    • 58 Posts
    I've been using the getParentField snippet (thank you @BobRay smiley) to help serve the page top content in a Revo 2.3.1-pl site.

      <section class="page-top">
        <div class="container">
          <div class="row">
            <div class="col-md-12">
         	     <h2><strong>[[!getParentField? &field=`pagetitle`]]</strong></h2>
                 <p class="page-top-description">[[!getParentField? &field=`introtext`]]</p>
            </div>
          </div>
        </div>
      </section>


    All is well until I enable jquery.pjax (https://github.com/defunkt/jquery-pjax) to ajax load partial page content; when trying to load certain pages, a 'Fatal error: Call to a member function get() on a non-object ... on line 3'

    $parentObj = $modx->getObject('modResource', $modx->resource->get('parent'));


    is returned.

    Been attempting to fix this for a while so any ideas very welcome. Thank you!
      • 3749
      • 24,544 Posts
      That's pretty baffling. It's saying that $modx->resource is not an object or not set, but it's always set in the front end and it's always the resource you're trying to view. My first thought was that you're trying to load a page outside of MODX, but in that case, the snippet wouldn't be running at all.

      You might see what the cache file for the resource looks like (in the core/cache directory).

        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
        • 5904
        • 58 Posts
        Quote from: BobRay at Nov 02, 2014, 11:05 PM
        You might see what the cache file for the resource looks like.

        Thanks for the tip, Bob. Getting a clearer picture now... Cleared the site cache and resources load well with pjax. However, if a resource is hard/fully loaded and then loaded again with pjax the error occurs (repeatable).

        The cache for such a resource looks like this:

        /core/cache/resource/web/resources:
        29.cache.php  336612 bytes
        
        /core/cache/resource/web/resources/29:
        7594f1d8a7d0f78c7e1cf37437d8f35c.cache.php  129 bytes 
        a9ed4a8106a1d6f61b5b29b3f66f6d2f.cache.php  256480 bytes


        I'm using the SwitchTemplate extra to respond to the pjax requests by query string.

        Suggestions for next steps welcome.
        [ed. note: craigphiz last edited this post 9 years, 4 months ago.]
          • 3749
          • 24,544 Posts
          What does the content of these files look like?

          7594f1d8a7d0f78c7e1cf37437d8f35c.cache.php
          a9ed4a8106a1d6f61b5b29b3f66f6d2f.cache.php

          It's possible that SwitchTemplate is causing the trouble. I looked at its code, but didn't see anything obvious.
            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
            • 5904
            • 58 Posts
            Thanks, Bob. I also suspected SwitchTemplate and disabled the cache, in the settings dialog on the SwitchTemplate manager page, but no change in the fatal error. Do you have any suggestions @Jako ?

            The smaller cache file looks like:

            <?php if(time() > 1415017023){return null;} return array (
              0 => 1185,
              1 => 200,
              2 => 54,
              3 => 10,
              4 => 30,
              5 => 3,
            );


            And the larger one is attached. Thanks again!
            [ed. note: craigphiz last edited this post 9 years, 4 months ago.]
              • 3749
              • 24,544 Posts
              I'm afraid I don't see anything helpful in either file.

              After disabling the SwitchTemplate cache, you should manually delete all files in the core/cache directory.
                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
                • 5904
                • 58 Posts
                Just discovered that there's an update for SwitchTemplate. Updated from v1.0.0 to v1.0.1 and, so far, browsing without the error smiley

                I'll post back if issue returns. Thank you for your help, Bob!
                  • 3749
                  • 24,544 Posts
                  Glad I could help. 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