We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40735
    • 119 Posts
    Hi guys!
    I'm getting into using xPDO for the first time and I'm reading through the docs here: http://rtfm.modx.com/display/xPDO20/Generating+the+Model+Code
    The very first step says "Create a PHP file where you have access to an xPDO instance." How do I do that? I imagine I could create a snippet and load it into a resource in MODx but I feel like that's not what it's asking of me. Also, will this process create tables in the database? I have already created them and populated them with some data so if it tried to create them I would expect it to fail.
    Thanks!

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      one easy way to create your package and basic xml-schema from existing table(s) is to use MIGXs package-management-feature.

      once installed correctly, there is a button 'create package' and 'write schema'

      I would give your existing tables a unique prefix other than modx_ before writing the schema.
      Then change your custom-prefix back to the default-prefix of modx_ and click the button 'parse schema' and you should be done.

      This is the way I do this stuff. Takes minutes to create a new xpdo-package this way.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 40735
        • 119 Posts
        Okay, so I'm trying to install MIGX. I downloaded the package and I'm walking through the steps in the readme but they say this:
        Actions-tree:
        migx -> right-click -> create Acton here
        controller: index
        namespace: migx
        language-topics: migx:default,file

        but I see this:
        http://img42.com/hMVZB

        What do I select for parent controller?
          • 4172
          • 5,888 Posts
          parent controller: none
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 40735
            • 119 Posts
            I tried that but it says I have to specify a parent action. There's no mention of language-tpoics or anything either.
              • 40735
              • 119 Posts
              Nevermind. I left it blank. That's not the same thing.
                • 40735
                • 119 Posts
                Okay, so I did that. It gave me an alert saying "success" a few times. Sweet! Can I now do something like the code below in my snippets or are there more steps?

                $path = MODX_CORE_PATH . 'components/myClass/';
                $result = $modx->addPackage('myClass',$path . 'model/','prefix_');
                  • 4172
                  • 5,888 Posts
                  check if your package and xpdo-classes and map-files really are created, since the processors of this feature allways return a 'success' - message.

                  if all went well, you should be able to use your new created xpdo-classes now.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 3749
                    • 24,544 Posts
                    Here is another easy way: http://bobsguides.com/custom-db-tables.html. It will create the schema and the class and map files for you.
                      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
                      • 40735
                      • 119 Posts
                      Quote from: BobRay at Feb 01, 2013, 06:36 PM
                      Here is another easy way: http://bobsguides.com/custom-db-tables.html. It will create the schema and the class and map files for you.

                      Hi Bob! I actually started with that guide but it was talking about some methods that parse and write the schema and I couldn't figure out how or where I was supposed to run these methods. My search led me to the docs I linked in my original post but they were only marginally helpful. They helped me understand that I need to create a PHP file somewhere that has access to xPDO but they don't say how to do that, which was my original question. Am I missing something in your guide?

                      Incidentally, the MIGX method does appear to work well but so far I haven't been able to get my package that it created to return anything other than an empty array.