We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25636
    • 21 Posts
    I’d like to access Zenphoto’s template functions within a MODx snippet as per the Zenphoto as a ’plugin’ user guide article. But I’m running into some trouble with MODx Revolution 2.0.7-pl and Zenphoto 1.4.0.2 (installed in the /zenphoto/ directory)

    I’ve attempted adding the suggested constant definitions and a require_once statement for the Zenphoto template-functions.php file to a chunk snippet which is then included in the template.

    Chunk Snippet 1:
    define('WEBPATH', 'zenphoto');
    define('ZENFOLDER', 'zp-core');
    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
    


    Snippet 2:
    $randomImage = getRandomImages();
    echo '<img src="'. $randomImage->getSizedImage(getOption('image_size')) . '" alt="random image - ' . $randomImage->getTitle() . '" />';
    


    This attempt returns the following (anonymised) error:
    Fatal error: Call to a member function getSizedImage() on a non-object in /home/username/domain.ca/core/cache/elements/modsnippet/46.include.cache.php on line 9


    The same code in a standalone PHP file returns a random image successfully.

    Someone found a solution for Evo back in 2008 by adding the constant definitions and require statement in the MODx index.php file. I understand this isn’t a great solution but I attempted it anyway with expectedly no success.

    Does anyone have any suggestions on how to get this working?
      Linux 2.6.32.8-grsec-2.1.14-modsign-xeon-64, PHP 5.2.14, MySQL 5.0.51a(client) 5.1.39-log (server), --with-pdo-mysql, Firefox/3.6.12
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Chunks cannot contain PHP code. Those definitions and include directives need to be in a snippet, or possibly a plugin.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 25636
        • 21 Posts
        You are right of course. I have, in fact, used two snippets.

        The suggestion I was using a chunk was a typo. I have corrected the original post.
          Linux 2.6.32.8-grsec-2.1.14-modsign-xeon-64, PHP 5.2.14, MySQL 5.0.51a(client) 5.1.39-log (server), --with-pdo-mysql, Firefox/3.6.12
          • 25636
          • 21 Posts
          sbillard over on the Zenphoto forums suggested that
          Errors like this are most likely caused by the zenphoto "include" being done from within a function. This has the effect of making Zenphoto global variables become "local" to the function.
          and that
          The best thing would be to figure out how to launch Zenphoto from not within a function call. (This is how Zenphoto does launch its plugins so that they do not suffer this issue.)

          Would using a plugin accomplish this?
            Linux 2.6.32.8-grsec-2.1.14-modsign-xeon-64, PHP 5.2.14, MySQL 5.0.51a(client) 5.1.39-log (server), --with-pdo-mysql, Firefox/3.6.12
            • 36509
            • 127 Posts
            Were you ever able to get modx and zenphoto to play nice together? I am struggling with it as I type!
              www.JBMWebDesign.com
              www.JBMAutomation.com