We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Thanks, that made my day. I’ll try to downplay documentObject as much as I can. wink it will probably only appear in the in-depth snippet section.

    What about implementing the get() method now? Maybe I could skip documentObject altogether.

    BTW, I could half-way make a case for leaving this out:

    // access some resource fields directly as object vars
    $id = $modx->resource->id;


    Unless it’s a lot faster than get(), since it would be easier to use get() all the time than to remember which fields you could get directly.
      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
      • 28215
      • 4,149 Posts
      Quote from: BobRay at Feb 26, 2009, 04:39 AM

      BTW, I could half-way make a case for leaving this out:

      // access some resource fields directly as object vars
      $id = $modx->resource->id;


      Unless it’s a lot faster than get(), since it would be easier to use get() all the time than to remember which fields you could get directly.

      I would always recommend using $obj->get(’field’) rather than $obj->field, for this reason:

      If for some reason down the line we decide to rename the column ’field’ to something else, ->field would not work. However, we could make ->get(’field’) work using internal aliases and logic, making it point to the new name.

      Neither is really ’faster’ in any measurable sense.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
      • Quote from: splittingred at Feb 26, 2009, 04:53 AM

        I would always recommend using $obj->get(’field’) rather than $obj->field, for this reason:

        If for some reason down the line we decide to rename the column ’field’ to something else, ->field would not work. However, we could make ->get(’field’) work using internal aliases and logic, making it point to the new name.
        In addition, many objects implement very specific logic in the get method for specific fields, so the raw value of the field may not be the same as the value retrieved with get(). In fact, this is the case with all of the timestamp fields represented in modResource, as well as many of the others.

        So, yes, you should always use the the get() (and set()) method to access the fields. But if you understand how the raw value is stored vs. how the get() method processes it, it sometimes does make sense to access them directly, though I should have specified only when you know the consequences and otherwise have a good reason to. This will be more important information for Core Extension developers, and I agree with BobRay that direct field access should be hidden from general usage examples in Snippets and Plugins.

        Quote from: BobRay at Feb 26, 2009, 04:39 AM

        What about implementing the get() method now? Maybe I could skip documentObject altogether.
        get() is implemented; this is the xPDOObject->get() method that all objects in the Revolution API have available.

        Quote from: BobRay at Feb 26, 2009, 04:39 AM

        since it would be easier to use get() all the time than to remember which fields you could get directly.
        It also doesn’t cause PHP errors when you try to access non-existent fields using the get() method, like it does if you try to access an object var that does not exist.