We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    It’s a little rough, but here it is: http://bobsguides.com/custom-db-tables.html. You may have to update to the latest version of MODx Revolution to get it to work (it definitely works on 2.0.4-pl or newer).

    Please let me know if you run into problems or have suggestions on improving it.

    [UPDATE 10/19/10] New version up at the link above. The snippet code is now downloadable here:

    http://bobsguides.com/assets/createxpdoclasses/create_xpdo_classes.zip

    Bob
      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
    • Thanks for taking your time to create a tutorial for us, I’m just having a read of it now. I’ll give some feed back, might not be today though.

      Cheers
        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
        AugmentBLU - MODX Partner

        BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • I followed your tutorial and copied everything as on your site, I created the same DB tables etc but I have this error.

        [2010-10-18 14:00:29] (ERROR in xPDO::connect @ /home/site/public_html/core/xpdo/xpdo.class.php : 318)
        
        SQLSTATE[28000] [1045] Access denied for user 'nobody'@'localhost' (using password: NO)
        
        
        Fatal error: Call to a member function execute() on a non-object in /home/site/public_html/core/xpdo/om/mysql/xpdogenerator.class.php on line 103
        



        I’m using Rev 2.0.4pl. How come it’s not connecting to the DB automatically? Should I do the first part,

        $xpdo = new xPDO('mysql:host=localhost;dbname=mydatabase',
            $database_user,$database_password,$table_prefix);
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 3749
          • 24,544 Posts
          That part should be executing with the correct settings. Are you running it as a snippet? Are your trying to access the bobs_quotation table, or one of your own?

          You could try returning the Dbase settings before the new Xpdo call to see if they are correct for your DB.

            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
            • 16429
            • 254 Posts
            Great tutorial.
            Easy as it needs to be, clear as you want it.

            Now the inverse, creating a table from a schema, please smiley
            (lol, Revolution is beating on me hardly)
              kudo
              www.kudolink.com - webdesign (surprised?)

              [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
              • 3749
              • 24,544 Posts
              Quote from: kudolink at Oct 19, 2010, 02:57 AM

              Great tutorial.
              Easy as it needs to be, clear as you want it.

              Now the inverse, creating a table from a schema, please smiley
              (lol, Revolution is beating on me hardly)
              Thanks. smiley

              I’m not 100% sure about this, but I think that if you create the schema and run parseSchema(), xPDO will create the table for you the first time you call an instance of the class’s save() method.

              Did the tutorial actually work for you as written (or did you just read it)? I haven’t actually tested it using cut-and-paste from the web page to a snippet so I don’t really know if everything works yet.
                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
                • 16429
                • 254 Posts
                Only read it, just going to try it.

                Question
                Do I have to add this line
                $result = $modx->addPackage('quotes',$path . 'model/','bobs_');

                in every snippet I want to use my custom table mapping?
                I guess yes, that’s the part that makes me available the table in $modx, am I right?
                After that, I can use [tt]$modx->getCollection[/tt] or [tt]$modx->getObject[/tt] as I would with chunks or resources. Still right?

                I’m not 100% sure about this, but I think that if you create the schema and run parseSchema(), xPDO will create the table for you the first time you call an instance of the class’s save() method.
                Mmmm... having something like a "terminal" would be nice for this kind of things instead of creating a doc to run a snippet once and then delete the doc.
                  kudo
                  www.kudolink.com - webdesign (surprised?)

                  [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
                  • 3749
                  • 24,544 Posts
                  Quote from: kudolink at Oct 19, 2010, 03:15 AM

                  Only read it, just going to try it.

                  Question
                  Do I have to add this line
                  $result = $modx->addPackage('quotes',$path . 'model/','bobs_');

                  in every snippet I want to use my custom table mapping?
                  I guess yes, that’s the part that makes me available the table in $modx, am I right?
                  After that, I can use [tt]$modx->getCollection[/tt] or [tt]$modx->getObject[/tt] as I would with chunks or resources. Still right?

                  Yes, and yes.


                  Mmmm... having something like a "terminal" would be nice for this kind of things instead of creating a doc to run a snippet once and then delete the doc.
                  I generally create the tables in PhpMyAdmin and then run writeSchema() and parseSchema() on them -- although my tables tend to be pretty simple.
                    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
                    • 3749
                    • 24,544 Posts
                    OK, I worked through the tutorial using cut-and-paste from the web site. I did find one error that might be causing trouble.

                    In the following line, the ’q’ in `quotes` should be in lowercase (it’s fixed on the web site):

                    [[CreateXpdoClasses? &myPackage=`quotes` &myPrefix=`bobs_`]]


                    Otherwise, everything worked fine for me as is.

                    Package names should be in all lowercase because they will be used for directory and file names and it’s a MODx convention to have all directory and file names in all lowercase.
                      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
                      • 1778
                      • 659 Posts
                      Hello

                      @kudolink : To understand the ’from schema to tables’ way, I recommend you to download modExtra. It’s a sample (and simple) to build a simple 3PC. It’s an excellent starter point... Have a particular look at the "model/" directory and at the "_build" directory...
                      Hope this will point you on the right direction
                      Cheers