We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    Hello,

    When I use an xPDO class in a snippet, the snippet crashes and the error log shows:

    <Classname>::load() is not a valid static method.
    


    I presume this is an xPDO error... Correct?

    Secondly, what triggers this error condition?

    Thanks
      MODx Revolution / MAMP / OS X
      • 21257 MODX Staff
      • 730 Posts
      Is your load method actually a static method? If not, you need to call it like $object->load()
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 22303 MODX Staff
        • 10,725 Posts
        You appear to be trying to load a class that does not extend xPDOObject as non-transient. xPDO does not support this. You must extend xPDOObject which implements the load() and many other important methods.
          • 27519
          • 275 Posts
          Thanks for your replies.

          @netProhpET: I actually do not call the method. The error is raised (probably) as part of a validation process by xPDO when the class is loaded.

          @OpenGeek: I copied the class files below. The class always worked without problems. I’ve used it in CMP’s and snippets without that error popping up . The funny thing is that the specific snippet works ok when run like [[!snippet]] but throws this static method error when I try to use it as a custom hook in Formit. I have devised a hack to work around the problem but really want to understand what makes this happen.

          The class in the model directory:
          <?php
          class Cottage extends xPDOSimpleObject {
              public function __construct(& $xpdo) {
                  parent :: __construct($xpdo);
              }
          
          }


          The class in the mysql directory
          require_once (strtr(realpath(dirname(dirname(__FILE__))), '\\', '/') . '/cottage.class.php');
          class Cottage_mysql extends Cottage {
              public function __construct(& $xpdo) {
                  parent :: __construct($xpdo);
              }
              		
          }
          
            MODx Revolution / MAMP / OS X
            • 28215
            • 4,149 Posts
            Can you post the *entire* code of your hook?
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 11055 ☆ A M B ☆
              • 3,112 Posts
              @shaun,
              I have the similar situation which is indeed related with the FormIt’s hook.
              Nothing special with my code, everything is just as same as your Doodle tutorial, except that it is called by FormIt.

              One thing I notice that when the script reaches the xPDO’s call() method, the classname exists but it becomes !is_callable.
                Rico
                Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                MODx is great, but knowing how to use it well makes it perfect!

                www.virtudraft.com

                Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                Maintainter/contributor of Babel

                Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                • 27519
                • 275 Posts
                Quote from: splittingred at Feb 07, 2011, 12:16 PM

                Can you post the *entire* code of your hook?

                Here it is. Although it’s no longer a hook but a snippet I call in the "Thank you" page (after calling the FormitRetriever). So for that to work, I had to relay the $hook->getValue() calls to $modx->getPlaceholder() method as the snippet is no longer running in the "context" of Formit. Essentially the other elements of the snippet did not change. The initialisation (first three lines) were taken from the Formit snippet and add the correct package.

                <?php
                  require_once $modx->getOption('tariffs.core_path',null,$modx->getOption('core_path').'components/tariffs/').'model/tariffs/tariffs.class.php';
                  $tar = new Tariffs($modx,$scriptProperties);
                  $tar->initialize($modx->context->get('key'));
                  $cottageId = $modx->getPlaceholder('fi.cottage-id');  
                  $cottage = $modx->getObject('Cottage', $cottageId);
                  // add booking
                  $booking = $modx->newObject('Booking');
                  $booking->set('title', $modx->getPlaceholder('fi.title'));
                  $booking->set('name', $modx->getPlaceholder('fi.lastname'));
                  $booking->set('firstname', $modx->getPlaceholder('fi.firstname'));
                  $booking->set('email', $modx->getPlaceholder('fi.email'));
                  $booking->set('phone', $modx->getPlaceholder('fi.phone'));
                  $booking->set('country', $modx->getPlaceholder('fi.country'));
                  $booking->set('cottage', $cottageId);
                  $booking->set('arrival_date', date('Y-m-d', strtotime($modx->getPlaceholder('fi.arrival-date'))));
                  $booking->set('departure_date', date('Y-m-d', strtotime($modx->getPlaceholder('fi.departure-date'))));
                  $booking->set('tariff', $modx->getPlaceholder('fi.tariff'));
                  $booking->set('adults', $modx->getPlaceholder('fi.adults'));
                  $booking->set('children', $modx->getPlaceholder('fi.children'));
                  $booking->set('dogs', $modx->getPlaceholder('fi.dogs'));
                  if ($modx->getPlaceholder('fi.comments') == null) {
                    $booking->set('guest_comments', '');
                  } else {
                    $booking->set('guest_comments', $modx->getPlaceholder('fi.comments'));
                  }
                  $booking->calculateDeposit();
                  $booking->set('deposit_paid', 'N');
                  $booking->set('balance_paid', 'N');
                  $booking->set('confirmed', 'N');
                  $booking->set('booking_date', date('Y-m-d', strtotime('now')));
                  $booking->set('source', 'Go Skye website');
                  $booking->save();
                  
                  // update calendar
                  $calendar = new Calendar($cottage, $modx);
                  $calendar->markOccupied($booking->get('arrival_date'), $booking->get('departure_date'));
                  return true;
                ​

                  MODx Revolution / MAMP / OS X
                  • 28215
                  • 4,149 Posts
                  Here’s your problem:

                  $tar = new Tariffs($modx,$scriptProperties);


                  That should be:

                  $tar = new Tariffs($modx);


                  As $scriptProperties in a Hook is the FormIt call’s $scriptProperties, which would mean it would overwrite some paths and other core vars in your Tariffs class. You don’t want that. So simply don’t pass it in - you can in a Snippet, not in a Hook.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 27519
                    • 275 Posts
                    Thanks for the help! Very much appreciated
                      MODx Revolution / MAMP / OS X
                      • 19980 ☆ A M B ☆
                      • 275 Posts
                      Hi

                      as far as I see you were trying to load the form it placeholders, right?

                      In my case, I launch :

                      [[!FormIt?
                      &hooks=`email,redirect,FormItAutoResponder,addToDbHook`
                      &emailTpl=`EmailResults`
                      &emailTo=`[email protected]`
                      &redirectTo=`228`
                      &store=`1`
                      ]]

                      where FormItAutoResponder is an addon (http://rtfm.modx.com/display/ADDON/FormIt.FormItRetriever)
                      and addToDbHook is my php code in a snippet.

                      Here is the issue:

                      I was thinking that FormItAutoResponder will run and save the FormIt placeholders and my snippet addToDbHook will be able tp parse them like:

                      $name = $modx->getPlaceholder(’fi.name’);

                      but $name is always empty... >:(

                      Can you suggest why?
                        modx and ecommerce pro