We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49407
    • 159 Posts
    This is what the addPackage method looks like...

         /**
         * Adds a model package and base class path for including classes and/or maps from.
         *
         * @param string $pkg A package name to use when looking up classes/maps in xPDO.
         * @param string $path The root path for looking up classes in this package.
         * @param string|null $prefix Provide a string to define a package-specific table_prefix.
         * @return bool
         */
        public function addPackage($pkg= '', $path= '', $prefix= null) {
            $added= false;
            if (is_string($pkg) && !empty($pkg)) {
                if (!is_string($path) || empty($path)) {
                    $this->log(xPDO::LOG_LEVEL_ERROR, "Invalid path specified for package: {$pkg}; using default xpdo model path: " . XPDO_CORE_PATH . 'om/');
                    $path= XPDO_CORE_PATH . 'om/';
                }
                if (!is_dir($path)) {
                    $this->log(xPDO::LOG_LEVEL_ERROR, "Path specified for package {$pkg} is not a valid or accessible directory: {$path}");
                } else {
                    $prefix= !is_string($prefix) ? $this->config[xPDO::OPT_TABLE_PREFIX] : $prefix;
                    if (!array_key_exists($pkg, $this->packages) || $this->packages[$pkg]['path'] !== $path || $this->packages[$pkg]['prefix'] !== $prefix) {
                        $this->packages[$pkg]= array('path' => $path, 'prefix' => $prefix);
                        $this->setPackageMeta($pkg, $path);
                    }
                    $added= true;
                }
            } else {
                $this->log(xPDO::LOG_LEVEL_ERROR, 'addPackage called with an invalid package name.');
            }
            return $added;
        }
    


    The first "if" statement is the part that is failing.

    My code is this...

    $prefix = 'xyz_';
    $packagename = 'moarDataStuff';
    $classname = 'Grows';
    
    $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/');
    $modelpath = $packagepath . 'model/';
    
    // The variable has been swapped out for a static string to make sure.
    $modx->addPackage('moarDataStuff', $modelpath, $prefix);
    
    $grow = $modx->getObject( $classname, array( 'grow_id' => $_GET['id'] ));
    


    As you can see, I am clearly sending a string... I modified the "else" in xPDO addPackage to this...

    $this->log(xPDO::LOG_LEVEL_ERROR, 'addPackage called with an invalid package name: '.$pkg);


    The error in the manager is now; "addPackage called with an invalid package name: "

    So, it is very interesting and peculiar to me that I am passing the packagename with static string and yet it is somehow empty when it gets to the method addPackage.

    Any ideas on what is happening? I assume it is a failure in PHP at the server?

    I am seriously considering switching hosting providers because this is not an isolated incident. I have also had forms that would not submit and functions that would not fire when called. Very strange things that are not code errors, or they would be logged in the php error log, they aren't.

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

      • 3749
      • 24,544 Posts
      I've never seen anything like that. It's frustrating when you don't trust your server. You might look at the server's error logs.
        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
      • discuss.answer
        That's really weird. What happens when you modify the addPackage function to do a var_dump before the if check? The benefit of var_dump is that it shows the type of the variable, while putting it in the log statement will cast it to a string.
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 49407
          • 159 Posts
          Quote from: BobRay at Dec 29, 2014, 10:35 PM
          I've never seen anything like that. It's frustrating when you don't trust your server. You might look at the server's error logs.
          Nothing was in the error logs about it. I started getting mem allocation errors in excess of 512MB which made no sense either.

          Quote from: markh at Dec 29, 2014, 10:51 PM
          That's really weird. What happens when you modify the addPackage function to do a var_dump before the if check? The benefit of var_dump is that it shows the type of the variable, while putting it in the log statement will cast it to a string.
          After I had them reset the server it worked fine. Go figure. I had them put me on a different server and I had to reinstall.

          Now I'm restoring from backup and have some caching problems from FormIt after removing the references to it in the database, should I just open another thread for that?

          I'm having a case of the Mondays. (facepalm)
            • 3749
            • 24,544 Posts
            I think that would be best as a new topic.
              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