We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 818
    • 23 Posts
    I created custom tables and all the directories and XML, everything works, I include the following code :

    $basePath = dirname(dirname(dirname(dirname(__FILE__))));

    require_once $basePath . ’/config.core.php’;
    require_once MODX_CORE_PATH . ’config/’ . MODX_CONFIG_KEY . ’.inc.php’;
    require_once MODX_CORE_PATH.’model/modx/modx.class.php’;
    $modx = new modX();

    include_once(MODX_CORE_PATH.’components/custom/functions.php’);
    $path = MODX_CORE_PATH . ’components/wishper_post/’;
    $result = $modx->addPackage(’wishper_post’,$path.’model/’,’wishper_’);


    I can query my new tables or Modx core table but when I try to save to modx Core table I get an error, this code:

    $newMember = $modx->newObject(’modUser’);
    $newMember->set(’username’,$_POST[’invite_email’]);
    $newMember->set(’password’,md5($pass));
    $newMember->save();

    give this error:
    Fatal error: Call to a member function get() on a non-object in /home/alaingab/public_html/core/model/modx/modx.class.php on line 1247

    If I remove the code to include my custom package it works fine.
    What am I doing wrong?

    thanks


      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Which line is number 1247? Why do you need to create a new instance of the $modx object? Is this used in a Snippet? The $modx object should already be available.
        • 26903
        • 1,336 Posts
        Call to a member function get()...
        This is failing on a get, not a set or save.
          Use MODx, or the cat gets it!
          • 3749
          • 24,544 Posts
          I suspect that it’s because you’re using a new, uninitialized $modx object instead of the real one that’s already available. If you’re using this in snippet inside MODx, all of this code at the top is unnecessary:

          $basePath = dirname(dirname(dirname(dirname(__FILE__))));
             
          require_once $basePath . '/config.core.php';
          require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
          require_once MODX_CORE_PATH.'model/modx/modx.class.php';
          $modx = new modX();


          If you’re using it outside of MODx, you need to add this:

          $modx->initialize('mgr');
            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
            • 818
            • 23 Posts
            thanks that worked!