We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Forgive me if this is the wrong place to post this, but I wanted to get some thoughts from the brilliant folks in here about how I might best go about creating some new pages for the admins/managers of a site. What I’d really like to be able to do is to use MODx to interact with some custom tables that I develop. I know that the base install can support a lot of what I need, but the database schema required by this client is extensive... I’ve got most of it sketched out so that it qualifies for first degree normalization. Here’s an example of some of the tables I need:

    Store Names : includes address, time-zone, phone-numbers, square feet
    People: first and last names, date of birth, date of death, bio (yes, the built-in tables might be able to cover this, but these people need to be separate from any web users)
    Countries: abbreviations, country code (This one is simple enough, I might just use a file and reference it via the @FILE binding or via a defined Template Variable ... although the list might be too long)

    The easiest place to start would be creating pages for the managers to simply READ what’s already in the database tables. I was hoping the DataGrid widget could help me out, but that’s not looking too good since the documentation is AWOL....

    Questions for pages that READ from new tables:
    1. How should I password protect these pages so that they are only available to the admins? Document Groups?
    2. Can anyone recommend a snippet / widget for displaying raw table data? Ultimately it’d be nice to use placeholders for templating, but if I just saw a raw table, it’d be ok for the beta version.

    Questions for pages that CREATE new Data:
    I’m not ready for specific questions yet, but can someone point me in the right direction for how MODx might handle a simple form? Eventually these forms will need to handle the insertion of new rows into these database tables and update the rows, and even delete them... but for now, I don’t even know how MODx might grab variables sent in a form submission (post or get).... where would you put code that reads those variables? I know how to do this with a normal by-hand site, but wow... fitting that into MODx is confusing me.

    Thanks for any ideas here!
      • 4310
      • 2,310 Posts
      If this is purely for back-end administration of input/viewing/editing/deleting custom table data then a Module would be the way to go.
      There is some documentation for Modules.
      Perhaps try installing something like Easy Newsletters to see module code in action.
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Yeah, for what it’s worth, the most useful thing that I’ve looked at so far is the Easy Newsletter module: http://modxcms.com/Easy-Newsletter-1589.html (thanks bunk58 for the good suggestion).

        This is definitely a step in the right direction. This module uses a custom table (that is created upon installation), and it has a nice form to accept data from the user to store into that table.

        I’m not clear on how to lock out non-admin users from the page(s) that might use something like this, but I think I can find this in the forums. The other thing that concerned me about this particular module’s Snippet is that its SQL statements are highly vulnerable to injection attacks, e.g.
        INSERT INTO `easynewsletter_subscribers` VALUES ('', '".$_POST['firstname']."', '".$_POST['lastname']."', '".$_POST['email']."', '', '', '', now()) 


        However, all that soap-box stuff aside, I’m still not entirely sure why this has to be a module and why a Snippet wouldn’t suffice... sure, I’d have to run my CREATE TABLE statements beforehand, but that’s not really a problem. Why is this a module and not just a Snippet?
          • 7231
          • 4,205 Posts
          The determining factor in a Module over a Snippet is how you want to manage it. A snippet will run in the front end and a Module will run in the manager. MaxiGallery and Jot are examples of snippets that create tables and provide editing directly in the front end. JoCo is an example of a Module that manages a table populated by a snippet from inside the Manger.

          Sottwell has a good module tutorial on her site. It could easily be adapted to your needs.

          I use modules to add function to the Manager, and 7 out of 10 times it will be some sort of CRUD interface (actually will be doing just that today). However with the modx API available the db tasks are very easy to code.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]