You can also define your own schemas for your own components and add them as packages - more on that in a future article.
Thanks, those articles are good... but unfortunately they only cover the built-in objects (i.e. MODx internals). The bit I’m looking for is how to interact with my own custom objects... but that’s not covered. The promising quote:
You can also define your own schemas for your own components and add them as packages - more on that in a future article.
I want to get things off the ground interacting with my own custom tables. If I could see a couple examples, I could get this going...
Thanks!
$modx->addPackage('mypackagename','/path/to/my/model/'); // ie, for a package "test" in your "core/components/myapp/model/test/' $modx->addPackage('test',$modx->getOption('core_path').'/components/myapp/model/');
$modx->getObject('test.myObject'); // or, alternatively, but a tiny bit slower, because it has to search for the package: $modx->getObject('myObject');
$modx->addPackage('captcha',$captcha_core_path.'model/'); $modx->loadClass('captcha.VeriWord',$captcha_core_path.'model/',true,true);
<?php //This line load the package captcha created with build.transport.php //If there are maps file located in the model directory, they will be loaded too so you can have access //To your table with xPDO. $modx->addPackage('captcha',$captcha_core_path.'model/'); //This line load the class called veriword.class.php located in the model directory //This is not directly related to xPDO. $modx->loadClass('captcha.VeriWord',$captcha_core_path.'model/',true,true);
<?php $this->modx->addPackage('yourpackage',$this->config['model_path'],'yourprefix_');
Nope, here, loadClass specifies that it’s a transient class - ie, it’s not directly related to a DB table. So we use loadClass, rather than newObject, because it’s not loading an xPDOObject-based object - just a transient, helper class.
How does loadClass() fit into this picture (assuming that it does)?
I would have thought you’d have to load a class before you could uses getObject(), new, or newObject() on it.
It think it would help if I knew what or where the class and package are being loaded or added *to*.
Part of my confusion stems from the fact that captcha.php has this code in it (I think you know how it got there ):
$modx->addPackage('captcha',$captcha_core_path.'model/'); $modx->loadClass('captcha.VeriWord',$captcha_core_path.'model/',true,true);
Is one or the other of these lines not needed or do they do different things?
(I hope this isn’t hijacking the thread -- I’m confused enough that I can’t tell).
$modx->addPackage('mypackagename','/path/to/my/model/');
// ie, for a package "test" in your "core/components/myapp/model/test/' $modx->addPackage('test',$modx->getOption('core_path').'/components/myapp/model/');
Well first you’ll need to parse the XML file and generate the object maps and class files:
Thanks for the input. Question: are you considering the XML schema your model? Could you please give an exact example? I’m sorry I’m so dense, but my mind can imagine that command pointing to several locations and working in several ways...
It’s targeting the PHP classes and maps.
Does the following example load an XML file in /core/model/schema/? e.g. /core/model/schema/mypackagename.mysql.schema.xml? Or is it targeting the PHP files that reference that XML file?
$modx->addPackage('mypackagename','/path/to/my/model/');
It can technically be whatever you want - we’ve just standardized that so people dont get confused.
If it’s referencing the XML, is it assumed that the format of the file name is "mypackagename.mysql.schema.xml"? If so, how do you change the database component (e.g. to Oracle or Mongo DB)?
It parses the PHP maps and classes.
// ie, for a package "test" in your "core/components/myapp/model/test/' $modx->addPackage('test',$modx->getOption('core_path').'/components/myapp/model/');
Again, does that command load up a PHP or an XML file?