We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27347
    • 65 Posts
    Did you have a look at the xPDO documentation?

    http://svn.modxcms.com/docs/display/xPDO20/Defining+the+Database+and+Tables
    http://svn.modxcms.com/docs/display/xPDO20/Defining+Relationships

    From this you can get an example of how to make a schema xml for your newsletter package.
      • 19909
      • 49 Posts
      sinnut,

      No, I hadn’t read those, I’ll take a look at them tonight. It seems to me that modxcms has become seriously overcomplicated in terms of addressing databases and their tables in comparison to evolution and straight sql ?

      Will there be a benefit to modxcms using xPDO ?

      regards,

      MM
        • 27347
        • 65 Posts
        Quote from: mmuller at Aug 01, 2010, 03:09 PM

        sinnut,

        No, I hadn’t read those, I’ll take a look at them tonight. It seems to me that modxcms has become seriously overcomplicated in terms of addressing databases and their tables in comparison to evolution and straight sql ?

        Will there be a benefit to modxcms using xPDO ?

        regards,

        MM

        I can’t answer your questions and i must say that this was my first impression as well. But after reading the docs some more it actually doesn’t seem overly complicated.
          • 28215
          • 4,149 Posts
          Quote from: mmuller at Aug 01, 2010, 03:09 PM

          No, I hadn’t read those, I’ll take a look at them tonight. It seems to me that modxcms has become seriously overcomplicated in terms of addressing databases and their tables in comparison to evolution and straight sql ?
          Will there be a benefit to modxcms using xPDO ?

          It is less complex than straight SQL, because xPDO does things that straight SQL doesnt do, namely:
          - Automatic parameter escaping, which prevents charset errors and sql injection attacks
          - Shorter code, because you dont have to do all the mysql_* functions
          - Easier to read code
          - Less error prone code due to abstraction
          - Abstraction between drivers, meaning that your xPDO queries will work in MySQL and the future drivers Revo will support (sqllite, postgresql, etc)
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 19909
            • 49 Posts
            Shaun,

            I get the abstraction and can ’read’ the xpdo queries and agree that the access to the data will be far easier but the problem comes in getting the models/classes built in the first place... Once I get this nailed then I think that the development of the CMP and the ’straight’ php processors will infact be relatively simple - especially as by using modext I get a very easy to use ’ide’ of sorts for the structure of the forms.

            However, I have to say though that the documentation is desperately vague as to how to setup everything - it almost expects you to be one of the modx team to understand what goes where etc etc.

            As of yet I still haven’t been able to get my build script to generate a single model file and I have now followed two different sets of instructions in the revolution documentation one from here:
            http://svn.modxcms.com/docs/pages/viewrecentblogposts.action?key=~splittingred

            and the other from here:
            http://svn.modxcms.com/docs/display/xPDO20/Generating+the+Model+Code

            Both the examples break the code down to an extent that they become illogical and hard to read (it almost needs a downloadable file of the example and an image showing where in the directory structure things should go) for example in the generate the model code:

            Loading xPDOManager and xPDOGenerator

            Create a PHP file where you have access to an xPDO instance. Then, let’s set the Log Target to the browser, and raise it a bit to get more detailed information.

            $xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO);  
            $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');  
            


            Now, we’ll want to load the xPDOManager and xPDOGenerator classes, to assist us with the model deployment.

            $manager= $xpdo->getManager();  
            $generator= $manager->getGenerator();  

            Setting Class and Map Templates

            Setting the Templates is completely optional. xPDO provides you with some basic templates that will work fine.
            By default, xPDO provides you with default class and map templates. For the purposes of this example, however, we want to create class files and maps with PHPDoc formatting at the top, so we’ll need to override the default class and map templates.

            To do so, we’ll just override the variables in the $generator object:

            $generator->classTemplate= <<<EOD  
            <?php  
            /** 
             * [+phpdoc-package+] 
             */  
            class [+class+] extends [+extends+] {}  
            ?>  
            EOD;  
            $generator->platformTemplate= <<<EOD  
            <?php  
            /** 
             * [+phpdoc-package+] 
             */  
            require_once (strtr(realpath(dirname(dirname(__FILE__))), '\\\\', '/') . '/[+class-lowercase+].class.php');  
            class [+class+]_[+platform+] extends [+class+] {}  
            ?>  
            EOD;  
            $generator->mapHeader= <<<EOD  
            <?php  
            /** 
             * [+phpdoc-package+] 
             */  
            EOD;  


            ’Create a PHP file where you have access to an xPDO instance’ <- what does that mean, I tried by having the file in a subdirectory with my schema but I get nothing...

            When I follow this and create a php build file in the folder with the schema I still get no results from the script... The examples aren’t starting from the right level - they expect an understanding that only the dev’s probably have as of now wink
              • 22303 MODX Staff
              • 10,725 Posts
              If you don’t want an object-oriented model for your database table, or to learn xPDO, and you want to write SQL, just use the PDO functions that are built into xPDO. PDO is the new standard for PHP database access, and you do not have to create a model for your application. Those that would like to though, can.
                • 19909
                • 49 Posts
                opengeek,

                I want to use the xPDO - its just at the moment (i dont get it) the documentation seems to have a few gaps in the explanations - as I said where do I put the build.myplugin.php file that calls the xPDO generate classes to build the model files ?

                I have this in the build file ’build.mmNewsletters.php’:

                <?php
                
                $xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO);
                $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
                
                $manager = $xpdo->getManager();
                $generator = $xpdo->getGenerator();
                
                $generator->parseSchema('./schema/mmNewsletters.mysql.schema.xml','./model/');
                ?>



                and this in my ’mmNewsletters.mysql.schema.xml’ a folder deeper than the build file:
                <model package="mmNewsletters" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM"
                     phpdoc-package="mmNewsletters" phpdoc-subpackage="">
                
                    <object class="mmSubscribers" table="mmSubscribers" extends="xPDOSimpleObject">
                        <field key="mmsub_name" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                		<field key="mmsub_email" dbtype="varchar" precision="255" null="false" default="" />
                		<composite alias="SubscribedTo" class="mmSubscribedTo" local="id" foreign="Subscribers" cardinality="many" owner="local" />
                </object>
                    <object class="mmNewsletters" table="mmNewsletters" extends="xPDOSimpleObject">
                        <field key="mmnew_newstitle" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                        <field key="mmnew_newsletter" dbtype="text" phptype="string" null="false" default="" />
                		<field key="mmnew_templateid" dbtype="int" precision="10" null="false" default="" />
                		<composite alias="SubscribedTo" class="mmSubscribedTo" local="id" foreign="Newsletters" cardinality="many" owner="local" />
                </object>
                    <object class="mmSubscribedTo" table="mmSubscribedTo" extends="xPDOSimpleObject">
                        <field key="mmsto_subid" dbtype="int" precision="10" phptype="string" null="false" default="" />
                        <field key="mmsto_newsid" dbtype="int" precision="10" phptype="string" null="false" default="" />
                		<aggregate alias="subscriber" class="mmSubscribers" local="Subscribers" foreign="id" cardinality="one" owner="foreign" />
                		<aggregate alias="newsletter" class="mmNewsletters" local="Newsletters" foreign="id" cardinality="one" owner="foreign" />
                </object>
                </model>


                when I run the build through a browser I get no output on screen and no output in the model folder either...
                  • 3749
                  • 24,544 Posts
                  There’s no output because you’re not logging anything.

                  This may give you a start:

                  $xpdo->setLogTarget('ECHO');
                  
                  /* your stuff here */
                  
                  
                  $xpdo->log(xPDO::LOG_LEVEL_INFO, "Generating . . .");
                  
                  if ($generator->parseSchema('./schema/mmNewsletters.mysql.schema.xml','./model/') {
                          $xpdo->log(xPDO::LOG_LEVEL_INFO, "Generation succeeded");
                  } else {
                          $xpdo->log(xPDO::LOG_LEVEL_INFO, "Generation failed");
                  
                  }


                    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
                    • 19909
                    • 49 Posts
                    Quote from: BobRay at Aug 02, 2010, 01:17 AM

                    $xpdo->setLogTarget('ECHO');
                    
                    /* your stuff here */
                    
                    
                    $xpdo->log(xPDO::LOG_LEVEL_INFO, "Generating . . .");
                    
                    



                    Bobray,

                    Thats brilliant ! What exactly is /* Your Stuff Here */ that’s what I mean by the developers expect you to know the system inside out !

                    Can one of you provide a zip file with a development branch of a dummy plugin that would create a three field table, the script to populate the Models and where to place it in the modx install structure and then maybe just maybe I might - just get the process...
                      • 19909
                      • 49 Posts
                      BobRay, Ryan, Splitting,

                      Here is an example of how to fully document how to extend/develop a cms in a CMF with clear information on the underlying terminology used throughout. I must admit that having taken a look at this it is quite exciting - but I still love modxcms, it just seems somehow - overcomplicated now...

                      http://doc.silverstripe.org/tutorial:2-extending-a-basic-site <- and this is just to show how to extend the initial core page templating/admin area...

                      I am sure you guys can see that by providing clear examples of the processes necessary to develop within modx then the community and plugins will develop much quicker - in fact most of the available plugins are from one of the dev’s at the moment, I’m sure he would like a break wink

                      Regards,

                      MM