We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25141
    • 49 Posts
    Hi people,

    I am trying to create custom database tables (either in MODx or using an external database), then pull data from them, show it on my website and somehow (either from the front or the backend, or even via phpMyAdmin or whatever) edit the data.

    This sounds to me like one of the most basic requests for a CMS - but after hours spent trying to figure out all the development tutorials in the Documentation, I am still baffled.

    Could somebody please point me to a simple simple simple tutorial for this process?

    It shouldn’t be much more effort than creating the tables, maybe also even using phpMyAdmin, writing the snippet to retrieve the data and calling it - right? At least that was the procedure in Evo.

    Thanks!
    Rixe
      • 1343 ☆ A M B ☆
      • 2,213 Posts
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 25141
        • 49 Posts
        Hi &
        yes, I’ve checked Bob’s tutorial - but that seems like an awfully complicated process just to read some custom db tables ...
        I can’t believe that there is no simpler way to do that --- ?
          • 25141
          • 49 Posts
          No comments? Do I really have to go through the whole xpdo / schema / mapping procedure?
            • 28215
            • 4,149 Posts
            No, you can use PDO methods directly, since the modX class extends xPDO, which extends PDO:

            http://us2.php.net/PDO

            The benefit of using xPDO schemas and maps, though, is that they’ll work in multiple database engines, and are easier to read.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 31037
              • 358 Posts
              Quote from: rixe at Nov 17, 2010, 03:19 PM

              Could somebody please point me to a simple simple simple tutorial for this process?

              It is much easier than it seems:

              1. Create your tables in any way you’d like.
              2. Created the snippet "CreateXpdoClasses" with the code from Bobs guide, with no changes in the code at all.
              3. Run CreateXpdoClasses like this: [[!CreateXpdoClasses? &myPackage=`yourpackagename` &myPrefix=`your_table_prefix`]].

              Done.

              In the snippets where you want to use is, just put:

              $path = MODX_CORE_PATH . ’components/yourcomponent/’;
              $result = $modx->addPackage(’yourcomponent’,$path . ’model/’,’your_table_prefix’);



                • 25141
                • 49 Posts
                Yes, thanks guys, that is easier than it first seemed to be (for a complete php / xpdo / pdo beginner ...)

                I went through the tutorial step by step and it works. I had been daunted by wanting to access an external db, but of course I can just set one up in ModX ... So now I’ll start fiddling around with my real table setup - I’ll probably be back here veeery soon wink

                First question right away: are there already any tips or tutorials on the forum on getting data back into the database - I’d like to set up a kind of form (Manager or frontend doesn’t matter) for the user to add and edit database content. Should I start looking into Custom Manager Pages or is that something that could be done with a TV / snippet combination, or maybe even with Formit?

                Thanks! - R


                *UPDATE*
                I think I’ll be listening closely to Bruno & Bob here: http://modxcms.com/forums/index.php/topic,54753.20.html
                  • 22303 MODX Staff
                  • 10,725 Posts
                  If you need something in the manager UI, create a CMP. If you want to present this editing form on the front-end, use Snippets. It’s up to you. And generally, processing such a form with a Snippet boils down to doing something like:
                  $myXpdoObject->fromArray($_POST);
                  $myXpdoObject->save();
                  Assuming you are using the actual field names in the form POST.

                  You could probably also do this with FormIt using a custom hook.
                    • 21884
                    • 57 Posts
                    i followed the instructions on bob’s page there, but all i end up with is testpackage.mysql.schema.xml in my "testpackage" directory in core/components/

                    the model folder has a subfolder called "testpackage" which contains an empty mysql folder, neither of the 2 folders contain files.

                    not getting any error messages either in the browser output or in my error logs, nor in the modx log.

                    my xml file only contains this (which seems a bit odd)
                    <?xml version="1.0" encoding="UTF-8"?>
                    <model package="testpackage" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
                    </model>

                      • 22019
                      • 390 Posts
                      @Lance - check your table name. When it outputs a blank model schema it’s because it can’t find the right table in the database.
                        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86