We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Hi, I'm trying to create a snippet that creates an odt-file. This is the library: https://github.com/cybermonde/odtphp

    This is my snippet:

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    require_once($modx->getOption('core_path') . 'components/odtphp/Odf.php');
    $odf = new odf(MODX_CORE_PATH .'components/odtphp/templates/test.odt');
    $odf->setVars('title', 'Dit is een testtitel');
    $message = 'Dit is de inhoud';
    $odf->setVars('message', $message);
    $odf->exportAsAttachedFile();
    ?>


    I placed the files in the correct folder. (core/components/odtphp/)

    Without the first two lines the page just doesn't display (500 internal server error). With the two lines I get:
    Fatal error: Class 'odf' not found in /home/domain/domains/mydomain.nl/public_html/core/cache/includes/elements/modsnippet/137.include.cache.php on line 14

    Does anyone know what could be wrong? Is it possible to do this in MODX like this at all?
    Thanks for any help!! [ed. note: michelle84 last edited this post 10 years ago.]
      • 36446
      • 184 Posts
      Quote from: michelle84 at Sep 21, 2016, 05:18 AM

      <!--?php
      ...
      require_once($modx--->getOption('core_path') . 'components/odtphp/Odf.php');
      ...
      


      Could it be that you have missspelled Odf.php? just in case - this can be the cause... it should be odf.php


        https://www.beautyislife-shop.de - premium make-up!
        https://www.topsterne.de - sell it here!
        ---------------------------------------------------------
        • 19328
        • 433 Posts
        Thanks flanger, but the file is actually named Odf.php so that should be ok I think.
        After some more investigation I'm thinking it might have something to do with the fact that this project is using composer. There seem to be a lot of dependencies that are not working. I'll see if I can get it going.
          • 36446
          • 184 Posts
          ah okay, just thought that could be the problem smiley then good look with it i hope you succeed!
            https://www.beautyislife-shop.de - premium make-up!
            https://www.topsterne.de - sell it here!
            ---------------------------------------------------------
            • 19328
            • 433 Posts
            thanks!!
              • 3749
              • 24,544 Posts
              If you look in the Odf.php file, is the class actually called 'odf' in the class declaration at the top (after the word "class")? Usually, class names start with an upper-case letter.
                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
                • 19328
                • 433 Posts
                No, it's Odf with uppercase, but when I try 'new Odf(....' I still get the same error...
                  • 3749
                  • 24,544 Posts
                  What does the __construct() function in that file look like?

                  It's definitely line 6 of your code above that's failing.

                  Is it possible that the constructor is looking for a URL instead of a path as the argument.

                  Or maybe there's something wrong with the test.odt file.

                  It's also possible that there should be an autoloader registered to make sure other sub-classes are loaded.
                    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