We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Try $this->modx->log(), $this->modx->getObject().

    Make sure you have this in the constructor:

    $this->modx =& $modx;
      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
      • 49407
      • 159 Posts
      As soon as I add $this->modx =& $modx; to the constructor I get the fatal error regarding getOption.
        • 3749
        • 24,544 Posts
        Are you sure that the $modx you're sending to the constructor is the real instance of $modx?

        Is there another $modx-> call in your code that might not have $modx set?
          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
          • 49407
          • 159 Posts
          Quote from: BobRay at Oct 09, 2015, 04:21 PM
          Are you sure that the $modx you're sending to the constructor is the real instance of $modx?

          Is there another $modx-> call in your code that might not have $modx set?

          This is happening on site load. If I try to access the manager or the front end I get a blank page and that error. So, it appears that when the current user object is created there is no $modx object being sent to my new class extuser.class.php.

          Also, the existing admin user class_key was automatically changed from modUser to extUser, but when I create a new user in the manager, or via the front end using the login extra the class_key is always modUser for new users.

          I thought that the system setting extension_packages [{"extendeduser":{"tablePrefix":"ext_","path":"[[++core_path]]components/classextender/model/"}}] was supposed to switch new users to extUser class_key? No?
          [ed. note: aaronkent last edited this post 11 years ago.]
            • 3749
            • 24,544 Posts
            I don't know where that error is coming from. Do you have code that's running outside of MODX or before the $modx object is instantiated?

            All the extension_packages System Setting does is load the class on every page load.
            You need a line in the class file to set the class_key.

            class extUser extends modUser {
                function __construct(xPDO & $xpdo) {
                    parent::__construct($xpdo);
                    $this->set('class_key','extUser');
                }
            }


            If you want to create users in the Manager, you also need a plugin attached to OnUserFormSave() with this code:

            $user->set('class_key', 'extUser');
            $user->save();
            return '';


            I'm tempted to repeat my suggestion that you create the table with the extra fields, but not change the class_key, then just use a snippet to send the messages rather than a class method. I think you could also have your class method, leave the class_key alone and do something like this, since the class is loaded:

            extUser::SendNotification($modx, $user);


              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
              • 49407
              • 159 Posts
              Thanks for all your help, BobRay. So far I think I've got things working the way I wanted with the method, thanks to your guidance and patience with me.

              I opted to pass the $modx instance to the sendNotification function rather than add it in the extUser class constructor. I'm not getting that getOption error now and I'll be testing the method once I get finished writing it.
                • 3749
                • 24,544 Posts
                I'm glad you got it working.
                  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