Hello,
I have more or less finished my property rental component in terms of CMP’s and related logic. I now want to use some of its features and information in a website, for example publish information about properties, price information, availability calendars etc.
I had a look at some of the components that come with MODx (Gallery, Quip) and noticed that the "processor" directories have separate subdirectories called "web" and "mgr". I assume "mgr" relates to the manager backend and "web" relates to the web frontend.
Lets assume I would want to write a simple snippet that accesses the model classes that make up the price structure of a rental property (basically a price list). Can I just access the XPDO model classes in my snippet and use a chunk to publish or is not as simple as that? If not, what would be the proper approach?
Also, am I correct to assume that - say - I wanted to maintain properties via the web frontend, I would write those as processors in the web context, e.g. in the "web" subdirectory of my processors?
Thanks.
MODx Revolution / MAMP / OS X
MODx Revolution / MAMP / OS X
Just write snippets that use addPackage() to add your model, and go from there.
shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect |
github |
splittingred.com
Thanks. I was stuck there. I copied your approach from Formit where you instantiate the Formit class. So, I instantiate my Tariffs class (copied from your Doodles and Modextra apps) which - in its constructor - happens to have the following line:
$this->modx->addPackage('tariffs',$this->config['modelPath']);
It all makes sense now...
MODx Revolution / MAMP / OS X
It’s less important since you have it working, but it’s a good practice to check the return value of addPackage(). It will return false if it fails.
That’s actually good to know. Thanks.
It also means that - as the addPackage is now hidden in the constructor - a failed add is not caught. At least not when following Shaun’s approach.
Just a thought: should these kind of methods not throw an exception in stead of returning a boolean when they fail? As it would be an exceptional situation (directory missing, installation failure, authentication issue at OS level) an exception requires an error handler....
MODx Revolution / MAMP / OS X