I love MODX and truly MODX gives me a lot of power.
I am not a developer by any means, but using MODX I have designed and created close to 100 websites - a few of them high traffic and well performing websites - without knowing any programming language outside of HTML/CSS. While I am not the most active person in the forums I am a regular promoter of the platform to users of all skill levels even though I am always in fear that I am letting them in on my little secret!
Any way I am in need of some assistance and I hope and I hope you can support me. I created two tables within the same DB as MODX with some various bits of information that I wish to pull into (and likely cache) my MODX resource. My goal is to create a TV for which I will place an ID code then using a snippet I wish to pull results from a certain DB column.
There will be two flavors of this so I will likely need two snippets. The first to pull all matching entries for the TV-entered ID code and place results in table rows that I will template.
The second flavor, from a second table will only contain a single matching DB row and I wish to pull the data from a specific column and display it wherever in the document a specific placeholder.
Probably really simple for some of you more experienced people, and you probably wonder how I have survived without knowing these basics - the answer is it is time to learn.
-
☆ A M B ☆
- 24,524 Posts
Thanks Susan, I followed the info at Bob's site and got lost. I wasn't able to follow it.
I've been looking at MIGxDB and that too has me a bit lost.
The method at my site for custom DB tables is not as complicated as it looks, you just have to follow the steps. You're ahead of the game in that you've already created the tables. Following the steps in the article will automatically create the class and map files that let you use xPDO methods with your custom tables.
That said, you don't have to do it that way. The point of the method I describe is that you can then use xPDO to handle getting and setting the data for you, but in a snippet, the $modx variable is a handle to the MODX database. As long as your tables are in there, you can write your own queries using PDO or MySQL if you want to, xPDO is just a lot more convenient.
-
☆ A M B ☆
- 24,524 Posts
Well, if you do want to use regular PHP mysqli queries, you have to make a new connection to the database. MODX initiates a PDO connection right away, so PDO queries work out-of-the-box. But it is worth the time to learn how to create the class and map files and use the xPDO API methods.
Quote from: jisaac at Jul 24, 2014, 06:47 PMThanks Susan, I followed the info at Bob's site and got lost. I wasn't able to follow it.
I've been looking at MIGxDB and that too has me a bit lost.
To get the idea, I would recommend doing that tutorial:
http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.create-doodles-manager-with-help-of-migxdb
Guess it just comes down to the fact I don't know PHP so even wrapping my head around the PDO means I should have some basic understanding.
It's going to be tough to deal with custom database tables without knowing some PHP.
BTW, there's a nice PHP primer in the Appendix of my book that I think is a good way to get started for PHP newbies:
http://modx.com/learn/modx-books/modx-the-official-guide/
-
☆ A M B ☆
- 24,524 Posts
If you've done any programming at all, PHP shouldn't be to difficult to pick up.
The one thing that it is absolutely essential to study and study well is how to write secure code. You can't just take any old input you get and throw it at the database. You have to check it to make sure it's generally what you are expecting to get, and then "escape" it so that even if somebody does sneak something nasty through, it won't do anything.
https://www.addedbytes.com/articles/writing-secure-php/
http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets