We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37335
    • 13 Posts
    Well I can't tell what's wrong. I tried checking the class_exists inside MagazineManagement and added some logging messages. The getService call works, and the class is run, but when checking if the Subscriber class exists, it returns as false. So the addPackage method doesn't even work in there.

    The create processor that adds magazines in the manager loads the Magazine class just fine though, because that part is working fine.

    The addPackage method is given the right package name and correct spelling, and an absolute path to the model folder, which is also correctly spelled.

    By the way, how does addPackage know what classes the package includes? Does it check metadata.mysql.php or something? [ed. note: edgefive last edited this post 14 years, 4 months ago.]
      • 9102 ☆ A M B ☆
      • 318 Posts
      I had the exact same problem while doing almost exactly the same thing, except that I was trying to use an extended modUser class. I have no idea what the problem is.

      I was able to get it to work by adding my package to the Extension Packages so it is loaded when MODX starts, and then not loading it up as a service. You can do that by adding it manually to the Extension Packages system setting, or by calling this just once (put it in a resolver if you're using a build script).

      $modx->addExtensionPackage('mypackage','/path/to/mypackage/model/');
      


      Since I'm loading the package as an Extension Package, I actually removed the addPackage line from my service class, which allows me to load the service class and its methods without breaking the model. I looked at the source code for Articles, and that's what splittingred does with his service class: he just loads up the lexicon, and doesn't add the package since it is added as an Extension Package in order to use the custom resource class.

      I think this is a bug, honestly, having something to do with the way hooks work in formIt. However, this workaround seems to be working for me at the moment.
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        By adding it as an extension package it's loaded everywhere - even when not used, so it does add some overhead throughout.

        It would be good to know if this is only happening in formit or also outside of it.
          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.
          • 9102 ☆ A M B ☆
          • 318 Posts
          In my case it only happens within formIt. However, I need to load the package as an extension anyway, because it has both a CRC and a modUser extension.
            • 37335
            • 13 Posts
            I tried adding it to the extension packages through system settings, and then commenting out the addPackage line in the main class. No joy. It still doesn't find the Subscriber class. I'm positive I entered it correctly as well. Also cleared the core/cache/ folder to be sure.

            Something very weird is going on. I'm on the latest version of Login and Revo by the way, don't think I mentioned that.

            As far as I can tell there's nothing wrong with the package? I've compared it to multiple addons and the syntax matches up. :S

            EDIT: Just did a 33rd test (judging by user ids) and removed the
            var_dump(class_exists('Subscriber')); die;
            line from the postHook. Now it went through just fine. Apparently the class itself doesn't exists, but MODX still finds it when it's trying to create the object. So the extension package solution actually worked.

            Atleast I can continue with my project now, but something is clearly going on with FormIt/Login hooks and addPackage. The overhead as Mark mentioned is a little disappointing, but this solution will have to do for now.

            Thanks a bunch to everyone who have posted! [ed. note: edgefive last edited this post 14 years, 4 months ago.]