Back to Top

How to Import Users in MODx from CSV file

Before few days, I have explained To send mail in modx and Execute Custom Query IN MODx and Today I am going to explain how to import users by external CSV file in MODx Revolution.

Well, I am going to explain to import user from an external script rather than using snippet or any resource in MODx Revolution.
First off, Let’s check how to load MODx object in external PHP file instead of as a snippet on an MODx resource, following line of code is useful.

Above code will initialize the MODx object into the web. Now, if you want to access it under a different context, you’ll just need to change the web to whatever Context you want to load into the initialize. This also loads the MODX error handler as well.

Above Code is used to get data from the CSV file and here I have pushed the data into the array $ausers.

Now, Lets set array data by using the following line of codes:

Let me explain above code here.First off, I have checked that user email address is unique by applying query.Then after I have created user and profile then set the user and profile value. Next save the user. After that, I have to get the last inserted user id and update the extended field of a user by using the set extended and send information mail to user.

Some more articles:

Accordion Menu with Modx
Move Modx Revolution to Live Server
To Reset resourceID in MODx

That’s it.I hope this script will helpful to externally import the user in Modx Revolution.I hope this post will help you. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (2)

  1. I keep getting an error that I can’t figure out with this:

    PHP Fatal error: Call to a member function fetchAll() on a non-object

    This is in reference to this line:
    $result = $stmt->fetchAll(PDO::FETCH_COLUMN);

    Any ideas? Thanks!

    1. Are you doing same mentioned in article?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Pagination in CodeIgniter

Posted on 6 years ago


How to use jQuery Lazy Load Plugin?

Posted on 4 years ago


How to use SQLite Database in PhoneGap?

Posted on 5 years ago