We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27889
    • 415 Posts
    hello,
    thanks for this great work which is XPDO.
    I’m trying to get & set tv for a front end document manager:
    I want to retrieve TV value from its name, but I surely do something wrong:

    $tv= $xpdo->getObject(’modTemplateVarDocument’, array (’tmplvarid’ =>’1’, ’contentid’=> $docm->get(’id’)));
    work well but if I try
    $tvdoctag= $xpdo->getObject(’modTemplateVar’, array (’name’ => ’documentTags’));// this don’t work
    to retrieve tv value from its name with:
    $tv= $xpdo->getObject(’modTemplateVarDocument’, array (’tmplvarid’ =>$tvdoctag->get(’id’), ’contentid’=> $docm->get(’id’)));
    it won’t work:
    Fatal error: Class ’modElement’ not found in /media/hda7/www/local/xpdo/om/modx096/modtemplatevar.class.php on line 2

    my schema (which I retrieve from noddy’s guide) for modtemplatevar is:

    ...
     <object class="modTemplateVar" table="site_tmplvars" extends="modElement"> 
            <field key="type" dbtype="varchar" precision="20" phptype="string" null="false" default="" /> 
            <field key="name" dbtype="varchar" precision="50" phptype="string" null="false" default="" /> 
    ...                  
            <field key="default_text" dbtype="text" phptype="string" null="false" default="" />                          
            <aggregate class="modCategory" key="id" local="category" foreign="id" cardinality="one" /> 
            <composite class="modTemplateVarTemplate" key="id" local="tmplvarid" foreign="id" cardinality="many" /> 
            <composite class="modTemplateVarDocument" key="id" local="tmplvarid" foreign="id" cardinality="one" /> 
            <composite class="modTemplateVarDocumentGroup" key="id" local="tmplvarid" foreign="id" cardinality="many" /> 
        </object>
    ...
    


    I have read the migration guide but don’t know/understand if it is the problem. I’m totally noob with XPDO and my skill with php is not the best one.
      MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
      MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
    • Soda:

      This definition requires something external. You can see this expectation in the schema definition for the object. It says extends="modElement", which means the generated class requires that such a class already be loaded before it is declared. modElement is what defines all the common properties and behavior of any MODx content element in 0.9.7, thus modTemplateVar is defined to extend this (as does modChunk, modSnippet, etc).

      That said, it’s not necessary to use this definition. What you can do is use xPDO to reverse engineer the database as is, which will create a pure schema (without any fk relations defined), then use this to generate the classes and maps. Instant CRUD. Then, when you want to use a specific object relation, define the aggregate/composite’s you want to utilize (you can study the 0.9.7 schema for ideas on defining some of these). In this way, you can slowly build up an API library for interacting with various MODx tables, as needed.

      I’ve done this on several projects so I didn’t have to re-implement all of the MODx functionality in these CRUD classes; just what I needed for the components I was building with them.

      Let me know what additional questions you have...

      Cheers
        • 27889
        • 415 Posts
        Thanks a lot OpenGeek, it works great now. I will play with all this aggregate and composite.
        I explain how I made, perhaps this can help:

        Edit : First get and install XPDO on 0.9.6

        get the shema and generate the class (executed once in a snippet):
        <?php
        global $modx;		
        include_once ( $modx->config['base_path'] . 'xpdo/xpdo.class.php');
        
        $xpdo= new xPDO('mysql:host=localhost;dbname=db_name', 'user', 'pass', 'table_prefix');
        $xpdo->setPackage('modx096');
        $xpdo->setDebug(true);
        
        //  initiate the manager
        $manager= $xpdo->getManager();
        $generator= $manager->getGenerator();
        
        //  reverse-engineer an existing database
        $xml= $generator->writeSchema(XPDO_CORE_PATH . '_model/096.mysql.schema.xml', 'modx096', 'xPDOObject', 'modx_');
        
        //  forward-engineer a model
        $generator->parseSchema(XPDO_CORE_PATH . '_model/096.mysql.schema.xml');
        ?>


        After that I can access my TV like this:
        Retrieve the TV named "documentTags" for document with id "9" and reset its value.
        <?php
        global $modx;		
        define('XPDO_MODE', 2);
        include_once ( $modx->config['base_path'] . 'xpdo/xpdo.class.php');
        $xpdo= new xPDO('mysql:host=localhost;dbname=local', 'root', 'apqlw;', 'modx_');
        
        $xpdo->setPackage('modx096');
        $xpdo->setDebug(false);
        
        $id= 9;
        $criteria= $xpdo->newQuery('sitecontent', $id);
        $criteria->limit(1);
        $docm= $xpdo->getObject('sitecontent', $criteria);
        if ($docm) { echo "DOC OK";} else {echo "DOC NOT OK";}
        
        $tvname= $xpdo->getObject('sitetmplvars', array ('name' => 'documentTags'));
        if ($tvname) { echo "TVname OK";} 
           else {echo "TVname NOT OK";exit;}
        
        $tvs= $xpdo->getObject('sitetmplvarcontentvalues', array ('tmplvarid' =>$tvname->get('id'), 'contentid'=> $docm->get('id')));
        if ($tvs) { 
          echo "TV OK";
          $tvs->set('value', 'That_s ok!');
          $tvs->save();
        } else {echo "TV NOT OK";}
        ?>


        I have a new toy and its call XPDO smiley
        I encourage all developper to post their XPDO codes to help others.
          MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
          MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
          • 14050
          • 788 Posts
          So if I get this correctly, you are using xPDO to accessing TVs in your 0.9.6 install from within a snippet in the new 0.9.7? That is pretty neat. I can’t wait to see more examples and then to actually have time to dive into xPDO.
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
          • xPDO works along side 096 (and earlier) projects just fine. It’s a separate standalone project unto itself. smiley

            http://xpdo.org/
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • Indeed; I’m putting together a sample 0.9.6-targeted xPDO-powered calendar project that does similar loose integration with web user data as another example of using xPDO with existing MODx deployments (no 0.9.7 required).

              I also have several developers using xPDO with Smarty and custom frameworks. One developer even used xPDO to reverse-engineer an osCommerce database, and replaced the osCommerce code with the xPDO model and Smarty views. The key is that xPDO allows you to get an instant object-oriented CRUD API from an existing MySQL database structure (and soon other database platforms), allowing you to interact with that data without the need to write SQL, but without in anyway limiting your ability to use even complex, platform-optimized SQL to perform custom business logic functions in your model.
                • 4172
                • 5,888 Posts
                I’m putting together a sample 0.9.6-targeted xPDO-powered calendar project
                Did you puplish this project anywhere?
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                • Quote from: Bruno17 at Aug 31, 2008, 05:54 PM

                  I’m putting together a sample 0.9.6-targeted xPDO-powered calendar project
                  Did you puplish this project anywhere?
                  I have not Bruno17; it was done for a client-project and I’ve never gotten around to polishing it up or documenting the features. I’ll see if I can’t squeeze it into a post this week to at least share the code and ideas of it.
                    • 4172
                    • 5,888 Posts
                    Quote from: OpenGeek at Sep 01, 2008, 02:49 AM

                    I’ll see if I can’t squeeze it into a post this week to at least share the code and ideas of it.
                    Thanks for your reply, OpenGeek. It would be of a great help to me.

                    Thanks for all of your work, Bruno
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 36416
                      • 589 Posts
                      Quote from: OpenGeek at Sep 01, 2008, 02:49 AM

                      Quote from: Bruno17 at Aug 31, 2008, 05:54 PM

                      I’m putting together a sample 0.9.6-targeted xPDO-powered calendar project
                      Did you puplish this project anywhere?
                      I have not Bruno17; it was done for a client-project and I’ve never gotten around to polishing it up or documenting the features. I’ll see if I can’t squeeze it into a post this week to at least share the code and ideas of it.

                      This would be really great, OpenGeek... wink