I'm exhausted trying to read-learn about xpdo...
I've gone through so many pages and tutorials and they all seems to have
a different way of doing things based on what version of revo, package and so forth.
I've gotten to the point of creating the tables via phpmyadmin and using CMPgenerator to create the schema and class files but now I don't know which way to turn... my head is spinning!
I'm currently going through the xpdo docs and am having a hard time figuring out what I'm doing...since i've created the packages, do I have to create a connection to the DB or do they automatically connect?
I've used the sample snippets that is supposed to connect and output connected or not but no matter what info I put in, always returns not connected and am not sure if that is even necessary.
I need to do two things with the db... first I need to able to access the data within the table like you would for manage users (thought I could use migx for this, but now Im not sure as it is seems to only apply to TVS) and I also need to have formit interact with the db to input and update via a front end form...
Are there any generic step by step guides? I've tried following Bobs guide and Using Custom Database Tables in your 3rd Party Components but they both have information that seems contradict.
I have worked with SQL (not mysql) and writing queries but xpdo is all very foreign to me, using snippets vs chucks or TVS etc.
I'm not sure what advice to give you, but maybe this will help.
To use xPDO with your custom table, you need to generate class and map files for it. My Tutorial creates a schema for you based on an existing MySQL table (or tables). The other tutorial you refer to has you create the schema yourself. Otherwise, the two tutorials should be about the same.
Once the class and map files have been generated, you don't need to create a connection to the database *assuming* that any custom tables are in the MODX database, not some other database. You *do* need to tell xPDO you want to use them by calling addPackage() or loadClass() for them. This has to be done before you call any xPDO methods (e.g., getObject(), getCollection(), etc.);
http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.addpackage
http://rtfm.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.loadclass
It's recommended that your custom tables be in the MODX database, but with a different prefix. You'll need to specify the prefix in any addPackage() calls.
-
☆ A M B ☆
- 24,524 Posts
The whole point of xPDO is to build on PHP's PDO to make a lot of the database work automatic. That's why the xPDO docs recommend getting familiar with the various design patterns used in its development.
Once you set up your classes, maps, etc, for a project then you can use all of the xPDO shortcuts to access and manipulate the database. After working in plain SQL it can take a bit of getting used to.
And, of course, none of this means that you can't access your database using plain-vanilla PHP sqli functions if you really want to.