We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14575
    • 21 Posts
    First I want to say that MODx looks really awesome smiley

    I was wondering how it would be best to implement some sort of database in MODx and how to force content editors to fill ceirtan fields for a database.

    Just as an example let’s assume that I want to create a database about NBA players. Let’s say that I store their points and assists after each game in one table and then I want to have a personal profile for each of them where I want ceirtan fields like age, short text about their youth, another short text about how their college years were etc.

    Before I saw MODx I guess I’d have created tables to hold that stuff and tried to write a little admin panel for the content editors where I would force them to fill at least some of those fields.

    If I want to do the same thing within MODx I guess I could do like in the old days but I was wondering if I wasn’t missing out then by not using the document tree (except for like two documents, one for content editors and the other to show the content)? Do you have any tips for a newb on how to work with databases like that and MODx?
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: jojo1313 at Apr 14, 2006, 11:34 AM

      First I want to say that MODx looks really awesome smiley

      I was wondering how it would be best to implement some sort of database in MODx and how to force content editors to fill ceirtan fields for a database.

      Just as an example let’s assume that I want to create a database about NBA players. Let’s say that I store their points and assists after each game in one table and then I want to have a personal profile for each of them where I want ceirtan fields like age, short text about their youth, another short text about how their college years were etc.

      Before I saw MODx I guess I’d have created tables to hold that stuff and tried to write a little admin panel for the content editors where I would force them to fill at least some of those fields.

      If I want to do the same thing within MODx I guess I could do like in the old days but I was wondering if I wasn’t missing out then by not using the document tree (except for like two documents, one for content editors and the other to show the content)? Do you have any tips for a newb on how to work with databases like that and MODx?

      You’ll want to become familiar with TV’s, or Template Variables. These are basically custom fields that can be attached to a template and values customized for each page that utilized that template. Thus, you could organize player pages that had TV’s attached to a players template, representing each of the data fields you want to collect. You could then create a page with a form for submitting a new player page, by filling in values for each of those TV’s (search for the NewsPublisher snippet for an example of how this might be accomplished; the example would be submitting a blog post that has some TV data associated), or simply create new player pages from the manager and then use the manager or the QuickEdit front-end editor to edit the TV values for each player page.

      This is not to say you couldn’t use a custom database to accomplish the same within MODx, but that is another approach to consider. In future versions of MODx, we will be introducing the ability to define and generate persistent objects at run-time in MODx, so you could create and maintain a table of custom data to use throughout your MODx site via a single, unified API, but enough teasing for now. TV’s should be a good starting point for you. Here is the documentation:

      http://www.modxcms.com/template-variables.html
        • 14575
        • 21 Posts
        Thank you very much for the very quick response  smiley

        I’ve been reading both the documentation for TV’s and the NewsPublisher code. I think I see how it could work but because I’m not entirely sure I’m going to post some more questions  tongue

        I think I see that the TV’s could for example depending on the document ID fetch the correct players stats and show them. But when I read the NewsPublisher code then everything just fits so extremely nice with the MODx database structure while a form for the basketball players doesn’t seem to behave as well at first sight. Wouldn’t I have to create a table containing all their stats which is linked to their page through the document ID? That puzzled me at first because I thought I would be losing some of the nice MODx overhead around documents. Then I started to think a bit about it and figured out that to edit those stats then people would have to do it through the form (for example) and hence the editedby, editedon,... variables indeed would be working. Then I thought if I wasn’t losing out on the search options for example if I was going to have multiple text fields and store them in some custom table. But then I thought that having a custom table was the wrong approach and I should of course split the various text fields into the various subdocuments and thus I’d keep all the benefits from MODx.

        I hope my thoughts are along the right way and I hope it provides some insight to the documentation team on how a MODx noob thinks  grin

        Edit: *Sigh* I’m pretty sure that what I write is making no sense at all. I promised some questions at the start of the post and here they are:

        - Datatypes like numbers that don’t seem to fit very well with the MODx database structure (unless I’m missing something big there) shouldn’t they be stored in some custom tables rather than in the content table?

        - If I want to have multiple text fields on a page and I want to force people to fill those out should I then store the various fields in sub-documents (that’s relative to the main one on the document tree) or am I creating too much overhead with it?
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: jojo1313 at Apr 14, 2006, 01:02 PM

          - Datatypes like numbers that don’t seem to fit very well with the MODx database structure (unless I’m missing something big there) shouldn’t they be stored in some custom tables rather than in the content table?
          That’s up to you, but I’ve had no trouble keeping any kind of data in the DB as a string of content, especially since PHP can automatically get it as the type it needs to work with in most cases. But beware of the range of numbers between 700 and 884 if using numeric data types.

          Quote from: jojo1313 at Apr 14, 2006, 01:02 PM

          - If I want to have multiple text fields on a page and I want to force people to fill those out should I then store the various fields in sub-documents (that’s relative to the main one on the document tree) or am I creating too much overhead with it?
          That sounds like a reasonable setup for the forms, though with some manager login permissions setup, you could easily have content editors able to use the manager or QuickEdit to edit the values without having to setup your own forms, and be restricted from editing other portions of your site.
            • 14575
            • 21 Posts
            Quote from: OpenGeek at Apr 14, 2006, 01:32 PM

            That’s up to you, but I’ve had no trouble keeping any kind of data in the DB as a string of content, especially since PHP can automatically get it as the type it needs to work with in most cases. But beware of the range of numbers between 700 and 884 if using numeric data types.
            Very true. It’s just that the site I’m working on has for example a database that currently has like 150 records, which each has like 60+ numerical fields and that database has to be able to handle over 1000 records so keeping every number as content just sounds scary because I feel the overhead will be too much and I think that good programming rules say that one should at least try to keep numbers in numerical fields in a database. So I guess I’ll have to mix up something myself to interact with MODx.

            There is one thing though that I’d love to see in MODx...
            The ability to create custom document types. For example having summarizing text might not fit for everyone so it would be cool to create a document type that wouldn’t contain it. Another example is that if you want like 2 or 3 text fields and then a few numerical fields. The reason why I think it’s cool is that by creating those then you can force your content editors to provide ceirtan data and so it is easier for you to deliver content in a consistent way. Another reason why I think it’s good is that it makes it easier to work with the data. For example if you had a bunch of documents about players and you wanted to analyze their points etc then it would be super to just have a column in the database with all their points. Of course it’s possible in the current system but I feel there is just too much overhead that follows it in the current system.

            So instead of having the content field and summarizing field in the current content table you have then you could have "pointers" to tables that actually contain the main content in your document. So when a user would create a new document type then he would basically be creating a new table in the database. I think this can work because there are very finite options of what kind of input you can have (for example rich text, short text like for titles and stuff, numbers, boolean fields and maybe fields where you are picking something from a finite number of options).

            One nice feature would be that maybe the main admin creates a folder, let’s call it player profiles, then creates a special document type for it. Then he assigns some content editors to that area and if they use the manager then one could have that new document type as the default document type for that folder and so when they are adding new documents then they get all the right fields up and what not.

            But wouldn’t that kind of system be too hard on new users with little CMS experience? Well of course you’d have the default document type and new users wouldn’t have to bother at all with creating new document types.

            But then again, I just might be whining and talking nonsense, lol. I know it aint good practice to throw out ideas and then not offer to help coding so I’m sorry about not offering to help :’( But then again the idea sounds like it would mean messing around with the core and if I were you I wouldn’t let a programming noob like me touch the core tongue
              • 25663 MODX Staff
              • 12,272 Posts
              What you’re asking for is in the 1.0 release plan. I think. LOL
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 14575
                • 21 Posts
                Awesome!
                *gives a big hug to the MODx team*

                Man, now I’m so excited about the release of version 1.0 that I’ll probably be asking "are we there yet?" way too often, lol.

                Well I think it’s awesome for MODx if it’s in the release plan for 1.0 because the CMS’s that I’ve tried this far all had some version of a blank page or default page but to be able to do what I tried to describe above then one had to hack the system. So not only will MODx outshine the other CMS’s in "buzzword compatability" and great looks but the content system will also be better and thus put you in a different league smiley
                  • 647
                  • 8 Posts
                  Hi jojo1313,
                  I was just searching the forum for solutions to the same problem as you posted here: integrating custom database tables in the framework of MODx. My impression is, that until now there is no straightforward way to do this. Using TVs might work but as all TVs seem to be stored individually in one database table this is (imho) a workaround at best, at least from an information architecture point of view.
                  What you are lokking for is a core feature of typo3. In typo3 it is very easy -- if you know how  wink -- to fully integrate custom database tables into the cms system and a great many of the numerous typo3 plugins do just this. You can define custom document types which are linked to matching custom forms in the typo3 backend (=manager) to add the appropriate information to the matching database tables. I need this feature very often, as many of my customers have some kind of structured content to manage: publications, events, products, persons, addresses etc.  all with unique attributes (= database fields).

                  It is not my intention to promote typo3 in this forum (even though I think typo3 is a very powerful cms framework). I want to underscore the point that an easy integration of custom data structures in MODx would in my opinion be a great advancement of this very promising CMS.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: aguen at Aug 21, 2006, 10:49 AM

                    It is not my intention to promote typo3 in this forum (even though I think typo3 is a very powerful cms framework). I want to underscore the point that an easy integration of custom data structures in MODx would in my opinion be a great advancement of this very promising CMS.

                    This is exactly what my xPDO project is about, though I take it step further to include forward and reverse engineering of database schemas, as well as auto API generation for all CRUD and foreign key relationship operations, automatic table-generation, and more. With it you can literally turn any MySQL structure into a light-weight, PHP 4 and 5 compatible OO API in a matter of minutes, and it works fine when used within the current MODx. I am working on examples of using this within the current MODx, and in fact, already have several live deployments using this to power custom database applications (including one with over 50 different custom tables).

                    I am just getting the web site underway, so feel free to ask questions about it if you have any interest in using it for a project. I certainly can’t say it’s bug free, but it’s definitely useful as a snippet developers tool, and like I said, I have various deployments using it successfully already. I even hope to have an add-on for 0.9.5 ready for usage soon, with some examples of adding tables for a custom web application, as well as for extending the capabilities of MODx itself using xPDO. And my MODx 1.0 rewrite is based on xPDO itself, so I believe any investment into working with xPDO would not be wasted as we move forward with the project.

                    Future development of xPDO will include the ability to easily port and optimize a schema/API to various database platforms. All that is required is an appropriate PDO driver for the platform. For PHP 4, this means custom PDO drivers will need to be authored, but I already have emulators for MySQL, PostgreSQL, and SQLite partially completed, and more could be easily implemented. And for those using native PDO on PHP 5.1+, xPDO takes full advantage of the native PDO extensions and drivers.
                      • 27226
                      • 186 Posts
                      Quote from: OpenGeek at Aug 21, 2006, 11:24 AM

                      if you have any interest in using it for a project. I certainly can’t say it’s bug free, but it’s definitely useful as a snipet developers tool, and like I said, I have various deployments using it successfully already. I even hope to have an add-on for 0.9.5 ready for usage soon, with some examples of adding tables for a custom web application, as well as for extending the capabilities of MODx itself using xPDO.
                      Ahem: I just came around and I am highly interested in this xPDO-DB stuff. Esp. when it can be used with the upcoming 0.9.5 release. TVs are no equivalent for real tables, they are just additions to one standard-table and all docs are forced to use them, whether they need them or not. And of course, having one doc per record is also not the approach I would like to take. The idea of selecting an external table, getting properly typed "magic-TVs" for each field, and being able to restrict them to those docs who actually use that template... it’s thrilling me! laugh

                      PS: as for the matter of data-types: numerical values should indeed be stored as numbers. Otherwise you could not do SQL-based calculations with them. I argue that the idea of a DB being a "one application only" resource is a bit limiting. DB-servers often serve their tables for more than one application, a CMS being only one of them. Just think of shops, logistics and the like.