We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21120
    • 30 Posts
    I’m writing a snippet to register new users. It works fine when i create the "standard" fields:
      $newProfile = $modx->newObject('modUserProfile');
      $newProfile->set('fullname', $newFullName);
      $newProfile->set('internalKey', $newUser->get('id'));
      $newProfile->set('email', $newEmail);
      $newProfile->save();
    

    However, i need custom fields to be saved... so I added "firstName" & "lastName" to the user_attributes table and tried this:
      $newProfile->set('firstName', $newFirstName);
      $newProfile->set('lastName', $newLastName);
    

    ...but it has no effect. so, how does one achieve this?

    thanks!
    -neil
      • 28215
      • 4,149 Posts
      splittingred Reply #2, 17 years ago
      1. You should never edit the default, core modx_ tables directly. This will cause many, many problems on upgrades.

      2. If you’re wanting to extend the modUserProfile classes, you can do that just by adding an xPDO aggregate relationship from your custom user profile class to the modUser object. There is a tutorial on adding custom table classes to your model here:

      http://svn.modxcms.com/docs/display/revolution/Using+Custom+Database+Tables+in+your+3rd+Party+Components

      3. It won’t add because the xPDO maps have not been updated to use your new fields. You would need to edit the schema file, and regenerate the maps. For more info on models, schemas and maps, see the xPDO schema documentation, here:

      http://svn.modxcms.com/docs/display/XPDO10/Creating+a+Model+With+xPDO
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 21120
        • 30 Posts
        so, i followed your tutorial word for word... I run build.schema.php, and i get a bunch of warnings:

        Notice: Use of undefined constant MODX_BASE_URL - assumed 'MODX_BASE_URL' in /Applications/MAMP/revo/core/model/modx/modx.class.php on line 991
        
        Notice: Use of undefined constant MODX_MANAGER_URL - assumed 'MODX_MANAGER_URL' in /Applications/MAMP/revo/core/model/modx/modx.class.php on line 1005
        
        Notice: Use of undefined constant MODX_ASSETS_URL - assumed 'MODX_ASSETS_URL' in /Applications/MAMP/revo/core/model/modx/modx.class.php on line 1009
        
        Notice: Use of undefined constant MODX_CONNECTORS_URL - assumed 'MODX_CONNECTORS_URL' in /Applications/MAMP/revo/core/model/modx/modx.class.php on line 1013
        
        Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/revo/core/components/extenduser/trunk/_build/build.config.php:3) in /Applications/MAMP/revo/core/model/modx/modx.class.php on line 2570
        
        Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/revo/core/components/extenduser/trunk/_build/build.config.php:3) in /Applications/MAMP/revo/core/model/modx/modx.class.php on line 2579
        Execution time: 0.0748 s
        [2009-09-29 23:43:42] (WARN @ /Applications/MAMP/revo/core/xpdo/om/xpdoobject.class.php : 932)
        
        PHP notice: A non well formed numeric value encountered
        


        but it does create 2 class files and a map file - so the directory structure looks exactly the same as in the tutorial.

        when i try to run the snippet, the database table isn’t created, and i get this error in the error log:

        [2009-09-29 23:40:10] (ERROR @ /index.php) Could not load class: extenduser from mysql.extenduser.

        and this:
        Fatal error: Call to a member function fromArray() on a non-object in /Applications/MAMP/revo/core/components/extenduser/trunk/core/components/extenduser/snippet.extenduser.php on line 23


        so, i’m not really sure what’s happening there... any help would be appreciated! thanks!
          • 3749
          • 24,544 Posts
          Did you perhaps forget this line in your build.schema.php?:

          require_once dirname(__FILE__) . '/build.config.php'; 
            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
            • 21120
            • 30 Posts
            Quote from: BobRay at Sep 30, 2009, 12:52 AM

            Did you perhaps forget this line in your build.schema.php?:

            require_once dirname(__FILE__) . '/build.config.php'; 


            No, that’s there - the only things i changed in the code from the tutorial were the paths. I did notice that if i comment out the initialize statement, the build.schema.php file doesn’t give me any warnings, but other than that the outcome is the same...
            require_once dirname(__FILE__) . '/build.config.php';
            include_once MODX_CORE_PATH . '/model/modx/modx.class.php';
            $modx = new modX();
            // $modx->initialize('mgr');
            $modx->loadClass('transport.modPackageBuilder','',false, true);
            
              • 28215
              • 4,149 Posts
              splittingred Reply #6, 17 years ago
              It’s going to be hard helping you without seeing the entire build file; could you post it?
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 22303 MODX Staff
                • 10,725 Posts
                Actually, I think this is a problem with the build.config.php. It should only contain two defines, one for the MODX_CORE_PATH and one for MODX_CONFIG_KEY. And the MODX_CONFIG_KEY is optional, needed only if you are working with multiple named configurations in one installation.
                  • 21120
                  • 30 Posts
                  OpenGeek, i tried your suggestion, but it still won’t load the class... Not quite sure what’s going on. I tried it with beta-3 and the latest SVN release, both on my MAMP server & on my web host; all 4 times with fresh installs.

                  I think it must be some sort of path problem, because i really had to hack away at changing the paths to get them to point to the correct places. for instance, the tutorial shows:
                  define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/MODxRevolution/');
                  but i had to use:
                  define('MODX_CORE_PATH', dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))."/revo/core/");


                  The error log message it gives is "(ERROR @ /index.php) Could not load class: extenduser from mysql.extenduser."

                  should this be "mysql/extenduser" instead??

                  If anyone wants to take a look, I’ve included a copy of the files and directory structure i’m using.

                  And there’s also the snippet call in revolution:
                  <?php
                  $base_path = $modx->getOption('core_path').'components/extenduser/trunk/core/components/extenduser/';
                  
                  $o = '';
                  $f = $base_path.'snippet.extenduser.php';
                  if (file_exists($f)) {
                     $o = include $f;
                  } else { 
                     $modx->setLogTarget('ECHO');
                     $modx->log(MODX_LOG_LEVEL_ERROR,'extenduser not found at: '.$f);
                  }
                  return $o;
                  ?>


                  Thanks!
                    • 13370
                    • 45 Posts
                    I think you hit the same problem as I did. There seem to be a bug in the tutorial, see http://modxcms.com/forums/index.php/topic,40565.0.html
                      • 21120
                      • 30 Posts
                      Quote from: Jacob at Oct 02, 2009, 04:15 AM

                      I think you hit the same problem as I did. There seem to be a bug in the tutorial, see http://modxcms.com/forums/index.php/topic,40565.0.html

                      AH! so simple! I could have sworn that i changed that, but i guess i didn’t. thanks for catching it!