We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    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
      • 27519
      • 275 Posts
      Nobody....?
        MODx Revolution / MAMP / OS X
        • 28215
        • 4,149 Posts
        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
          • 27519
          • 275 Posts
          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
            • 3749
            • 24,544 Posts
            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.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 27519
              • 275 Posts
              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