We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45950
    • 40 Posts
    I'm exhausted trying to read-learn about xpdo...

    I've gone through so many pages and tutorials and they all seems to have
    a different way of doing things based on what version of revo, package and so forth.

    I've gotten to the point of creating the tables via phpmyadmin and using CMPgenerator to create the schema and class files but now I don't know which way to turn... my head is spinning!

    I'm currently going through the xpdo docs and am having a hard time figuring out what I'm doing...since i've created the packages, do I have to create a connection to the DB or do they automatically connect?

    I've used the sample snippets that is supposed to connect and output connected or not but no matter what info I put in, always returns not connected and am not sure if that is even necessary.

    I need to do two things with the db... first I need to able to access the data within the table like you would for manage users (thought I could use migx for this, but now Im not sure as it is seems to only apply to TVS) and I also need to have formit interact with the db to input and update via a front end form...

    Are there any generic step by step guides? I've tried following Bobs guide and Using Custom Database Tables in your 3rd Party Components but they both have information that seems contradict.

    I have worked with SQL (not mysql) and writing queries but xpdo is all very foreign to me, using snippets vs chucks or TVS etc.
      • 3749
      • 24,544 Posts
      I'm not sure what advice to give you, but maybe this will help.

      To use xPDO with your custom table, you need to generate class and map files for it. My Tutorial creates a schema for you based on an existing MySQL table (or tables). The other tutorial you refer to has you create the schema yourself. Otherwise, the two tutorials should be about the same.

      Once the class and map files have been generated, you don't need to create a connection to the database *assuming* that any custom tables are in the MODX database, not some other database. You *do* need to tell xPDO you want to use them by calling addPackage() or loadClass() for them. This has to be done before you call any xPDO methods (e.g., getObject(), getCollection(), etc.);

      http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.addpackage

      http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.loadclass



      It's recommended that your custom tables be in the MODX database, but with a different prefix. You'll need to specify the prefix in any addPackage() calls.
        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
        • 45950
        • 40 Posts
        Quote from: BobRay at Dec 30, 2013, 02:59 PM
        I'm not sure what advice to give you, but maybe this will help.

        To use xPDO with your custom table, you need to generate class and map files for it. My Tutorial creates a schema for you based on an existing MySQL table (or tables). The other tutorial you refer to has you create the schema yourself. Otherwise, the two tutorials should be about the same.

        Once the class and map files have been generated, you don't need to create a connection to the database *assuming* that any custom tables are in the MODX database, not some other database. You *do* need to tell xPDO you want to use them by calling addPackage() or loadClass() for them. This has to be done before you call any xPDO methods (e.g., getObject(), getCollection(), etc.);

        http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.addpackage

        http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.loadclass



        It's recommended that your custom tables be in the MODX database, but with a different prefix. You'll need to specify the prefix in any addPackage() calls.

        Bob thanks for your help... in your guide you reference the doodle tutorial for creating custom manager pages however the link generates a 404 not found and in searching on "doodles" in the docs, all that is listed is using migxdb, but no matter what I do, I can not get this to work... spent hours trying to no avial... do you know the link to the tutorial you mention on your page?
          • 45950
          • 40 Posts
          Quote from: d1ckyh at Dec 30, 2013, 03:20 PM
          Quote from: BobRay at Dec 30, 2013, 02:59 PM
          I'm not sure what advice to give you, but maybe this will help.

          To use xPDO with your custom table, you need to generate class and map files for it. My Tutorial creates a schema for you based on an existing MySQL table (or tables). The other tutorial you refer to has you create the schema yourself. Otherwise, the two tutorials should be about the same.

          Once the class and map files have been generated, you don't need to create a connection to the database *assuming* that any custom tables are in the MODX database, not some other database. You *do* need to tell xPDO you want to use them by calling addPackage() or loadClass() for them. This has to be done before you call any xPDO methods (e.g., getObject(), getCollection(), etc.);

          http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.addpackage

          http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.loadclass



          It's recommended that your custom tables be in the MODX database, but with a different prefix. You'll need to specify the prefix in any addPackage() calls.

          Bob thanks for your help... in your guide you reference the doodle tutorial for creating custom manager pages however the link generates a 404 not found and in searching on "doodles" in the docs, all that is listed is using migxdb, but no matter what I do, I can not get this to work... spent hours trying to no avial... do you know the link to the tutorial you mention on your page?

          Actually I found the link via the migx tutorial... you may want to change the link you reference to http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/developing-an-extra-in-modx-revolution/developing-an-extra-in-modx-revolution,-part-ii
            • 3749
            • 24,544 Posts
            Done. Thanks!
              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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The whole point of xPDO is to build on PHP's PDO to make a lot of the database work automatic. That's why the xPDO docs recommend getting familiar with the various design patterns used in its development.

              Once you set up your classes, maps, etc, for a project then you can use all of the xPDO shortcuts to access and manipulate the database. After working in plain SQL it can take a bit of getting used to.

              And, of course, none of this means that you can't access your database using plain-vanilla PHP sqli functions if you really want to.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 45950
                • 40 Posts
                Quote from: sottwell at Dec 31, 2013, 01:00 AM
                The whole point of xPDO is to build on PHP's PDO to make a lot of the database work automatic. That's why the xPDO docs recommend getting familiar with the various design patterns used in its development.

                Once you set up your classes, maps, etc, for a project then you can use all of the xPDO shortcuts to access and manipulate the database. After working in plain SQL it can take a bit of getting used to.

                And, of course, none of this means that you can't access your database using plain-vanilla PHP sqli functions if you really want to.

                Thanks to All!

                Overthinking is what has tripped me up on this... it is so simple that you say to yourself; "It can't be this simple" when in fact following the guidelines produces the desired results smiley

                Bobs' tutorial is exactly what I needed to get me on the right path and am now excited VS frustrated in learning all of the ways to use xpdo...

                Thanks again for all who chimmed in to help