We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    I thought that the latest Ditto now came with an extender for accessing data from custom database tables, but when I look on the Ditto support site I can’t find any mention of it and it’s not in my extenders folder. Was I dreaming? Or is there code to do this out there and I just don’t know where to look for it?
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 7253
      • 97 Posts
      I was just thinking the same thing - I need this capability for a site and thought it was straightforward, but can’t find and docs, extenders or examples?
        • 4172
        • 5,888 Posts
        For displaying datas I use allways my template-system xett. You can display nested arrays in nested Templates. Initialy written for displaying events in calenders, the latest release can display all sort of nested datas.
        You can have different projects and for each project different actions (services). The templates and project include files (getdatas.php, onsavedatas.php) are organized as files in a folderstructure.

        for example you have a project scool.
        the snippetcall could be
        [!xett? &project_path=`scool`&service=`pupils_list`&canedit_webgroups=`editors`!]
        

        then in your projectfile you can have

        //first get the arrays $classrooms and $pupils with modx->dbApi
        //then store all that in the array $xettdatas 
        
        $classrooms['innerrows']['pupils']=$pupils;
        $xettdatas['innerrows']['classrooms']=$classrooms;


        in the Template xetouterTpl.html you can have:
        [+xett.innerrows.classrooms+]


        in the Template classroomsTpl.html:
        [+xett.row.teacher+]
        [+xett.row.roomsize+]
        <table>
        [+xett.innerrows.pupils+]
        </table>


        in the Template pupilsTpl.html:

        <tr><td>[+xett.row.name+]</td><td>[+xett.row.age+]</td><td>[+xett.row.adress+]</td></tr>



        It can also process formdatas and so on. This is only a very easy example.

        There is al lot of code for displaying calenders and so, you can remove if not needed. The coming release has also a cache-class included, so I can cache different month-views for example.

        Here on my Testsite you can see one example: http://www.meine-goldschmiede.de/testmodx/index.php?id=1122










          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 32645
          • 377 Posts
          I also need Ditto to look at a custom table, not only to output row data, but for templating, filtering, etc.

          According to the ditto.modxcms.com website and wiki.modxcms.com website, you can use the WHERE command


          (URL: http://ditto.modxcms.com/files/snippet-ditto-php.html#where)
          &where
          A valid MySQL WHERE statement using only document object items.

          &queryLimit
          Number of documents to retrieve from the database, same as MySQL LIMIT

          But does this mean that ditto can only look at the modx_site_content, or can it actually look at other tables?

          I’m going to try a test now, but if someone has been able to connect Ditto with another table, that includes pagination, that’d be great!

          Thanks

          [edit]

          It seems that WHERE doesn’t really look at other tables. I tried &where=`cars.car_model="ford"` as an example, it didn’t return any value.

          I don’t think its possible to use Ditto for external tables... maybe I’m wrong.
            • 7231
            • 4,205 Posts
            It is my understandin that the staement is saying that you can only use document objects and not template variables inthe WHERE clause.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 32645
              • 377 Posts
              I didn’t use a template variable.

              Perhaps if you can cite an example of how to use Ditto for external tables.
                • 7231
                • 4,205 Posts
                Wait a minute... this is just the WHERE part of the clause, you can’t assign a table in the WHERE part, that is done in the FROM part of the query. Or am I wrong?

                There is a cool snippet that is for returning data from the db and generating a Ditto like index. I always forget about it but I have used it before and it works well. It was not easy to find since it is not in the Repo (?) looDBchunk: http://modxcms.com/forums/index.php/topic,14654.0.html
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 32645
                  • 377 Posts
                  I see.

                  I’ve looked through the code, and Ditto only looks at the modx_site_content.

                  I’ll look at your example to see if I can use it to look at my holiday offers, which is a different table.