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

    I’m a mainly back-end php developer that is just starting out with modx. I just have a couple questions that mainly deal with adding back-end php code to an existing website that uses modx evo 1.0.

    Firstly, I just wanted to know what are the best practices right now for accessing (create/read/update/delete) mysql databases in modx evo 1.0. The tables are in the modx database.

    Is using the DBAPI what everyone uses? I am a bit confused why a lot of the API functions are highlighted red on this page: http://svn.modxcms.com/docs/display/Evo1/DBAPI
    Is this to indicate deprecation of some sort? I don’t believe PDO is supported so I am guessing this is the main option?

    The second question is pretty general and deals with OOP and may just be because I am not yet experienced with snippets. I wanted to encapsulate the db calls and other functions in a class and have functions be accessible as static functions. where is the best place to write the class definition? inside a snippet?

    Sorry if there are any ambiguities. Thanks in advance for any replies.
      • 16278
      • 928 Posts
      I think the ones in red on the page referred to are simply ones that haven’t been transferred in yet from the old Wiki at http://wiki.modxcms.com/index.php/API:DBAPI.
      smiley KP
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: deltascout at May 19, 2010, 11:06 AM

        Is using the DBAPI what everyone uses? I am a bit confused why a lot of the API functions are highlighted red on this page: http://svn.modxcms.com/docs/display/Evo1/DBAPI
        Is this to indicate deprecation of some sort? I don’t believe PDO is supported so I am guessing this is the main option?

        The second question is pretty general and deals with OOP and may just be because I am not yet experienced with snippets. I wanted to encapsulate the db calls and other functions in a class and have functions be accessible as static functions. where is the best place to write the class definition? inside a snippet?
        Revolution is built on PDO, and includes a very useful, but light O/RM layer called xPDO. This is the future of MODx, and if you are a developer just starting out, I might recommend investigating Revolution.

        Otherwise, in Evo the best way to include your own classes is by putting them in a separate file and using include_once (or check if class_exists() and include() if not) in a snippet to make sure it only gets loaded once if you are using a Snippet that loads your class multiple times.
          • 7006
          • 3 Posts
          Thanks for the replies guys. I’ve been reading a lot about MODx since then and it looks like the way to go.

          A question for OpenGeek, at the moment I am maintaining a site built on evo 1.0 which is why I feel hesitant to push forward with revolution techniques. Being co-creator, can you comment on porting a site from evo 1.0 to revolution for a large site? painless? feasible? not worth it?

          I have no problems starting new projects in revolution and I am looking forward to the ORM functionality. Just looking for best practices with existing evo sites.

          EDIT: laugh actually nevermind this last question. Just browsed around the forum. I’ll wait for possible guides.
            • 32699 ☆ A M B ☆
            • 427 Posts
            When you want to get into xPDO, I have slowly picked opengeek’s brain and written working examples to help you get started. Check my signature.
              Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

              Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com