We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23334
    • 2 Posts
    I am running Revo 2.0.7-pl(traditional), Windows 7, PHP 5.3.3, MySQL 5.1.50 on my local machine.
    I want to add users via a php script that takes its input from a csv file.

    I am receiving this error when setting up $modx->newObject(’modUser’):
    Fatal error: Class ’modPrincipal’ not found in C:\Server\Sites\modxtest\core\model\modx\moduser.class.php on line 7

    Why is core\model\modx\modPrincipal.class.php not found?

    Thanks for your assistance.

    Here is the code:
    <?php
    //
    // Input Roster.csv format:
    // username, password, fullname, mobilephone, phone, email 
    //
    require_once '../../config.core.php';
    include_once MODX_CORE_PATH . 'model/modx/modx.class.php';
    $modx= new modX();
    //
    require_once('parsecsv.lib.php');               # Include the parseCSV class
    $csv = new parseCSV();                          # Create a new parseCSV object
    $csv->delimiter = ",";                          # Use the comma delimiter
    $csv->enclosure = '"';                          # Use the double quotes enclosure
    $csv->parse('Roster.csv');                      # Parse the Roster.csv
    //
    foreach ($csv->data as $key => $row) {  
    
      while ($row[username] !== "") {
    
      /* Setup the user */
        $user = $modx->newObject('modUser', array('username'=>$row[username]));
        $user->set('active','1');
        $user->set('password',md5($row[password]));
    
      /* Setup the user's profile */
        $profile = $modx->newObject('modUserProfile');
        $profile->set('fullname', $row[fullname]);
        $profile->set('email', $row[email]);
        $profile->set('phone', $row[phone]);
        $profile->set('mobilephone', $row[mobilephone]);
        $user->addOne($profile);
    
      /* save the user to DB */
        $user->save();
    

      • 22303 MODX Staff
      • 10,725 Posts
      You need to initialize() a Context first, e.g.
      <?php
      $modx= new modX();
      $modx->initialize('mgr');
      //
      

      The modX->initialize() method is responsible for loading all the required classes, the cache manager, config, context settings, sessions, and much more.
        • 23334
        • 2 Posts
        Thank you sir.

        Quote from: OpenGeek at Jan 20, 2011, 12:25 PM

        You need to initialize() a Context first, e.g.
        <?php
        $modx= new modX();
        $modx->initialize('mgr');
        //
        

        The modX->initialize() method is responsible for loading all the required classes, the cache manager, config, context settings, sessions, and much more.