Aha. I figured this out and I’m updating the documentation to make it more clear. Here are my pointers.
1. Before using $modx->addPackage() remember that the $modx object is an instantiation of xPDO. If the database tables you’re trying to access are not inside the MODx database, you’ll need to instantiate a new xPDO object that points to that separate database a la
http://rtfm.modx.com/display/xPDO20/Database+Connections+and+xPDO
2. The 1st argument to the addPackage() method should be the
name of the folder which contains all of your tablename.class.php files and the mysql sub-folder with the tablename.map.php and tablename.map.inc.php files. Normally, the folder that contains the myriad class and map files lives inside the "model" folder inside your package folder, but strictly speaking, that’s just good housekeeping: addPackage() doesn’t care if you have a messy room, it just wants to know which sub-folder contains the map and class files. It’s not the full path, it’s just the folder name. The path to the parent folder is the 2nd argument.
3. The 2nd argument to the addPackage() method is the full path to the parent folder which contains 1 or many sub-folders which in turn contain the map and class files. Often, this argument makes use of the XPDO_CORE_PATH constant, but that’s just common usage and organizational preference.
4. the getCollection() method expects a class name, not a table name. So if your XML schema file defines your table like this:
<object class="NameOfClass" table="name_of_class" extends="xPDOObject">
then you’d access it via:
$members = $my_xpdo->getCollection('NameOfClass');
So altogether, my Snippet looks like this:
$my_xpdo= new xPDO('mysql:host=localhost;dbname=my_db','myuser','mypassword','');
$my_xpdo->addPackage('my_package','/path/to/parent/dir/model/');
$members = $my_xpdo->getCollection('NameOfClass');
echo 'Total: '.count($members);