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
    Quote from: sottwell at Aug 15, 2013, 03:52 AM

    With MyComponent, you work within the MODx system, exactly as your files will be when it's an installed component.

    That's not strictly true, since MyComponent has them in this location:
     
    [assets files] assets/mycomponents/componentsname/assets/components/componentname/
    [core files] assets/mycomponents/componentsname/core/components/componentname/
    


    When installed, they'll be at
    [assets files] assets/components/componentname/
    [core files] core/components/componentname/
    


    But with Shaun's trick with the System Settings in your includes, they'll run from your dev. location (under assets/mycomponents/) during development and from the standard locations when installed.

    Here's the include for the Notify class. The nf.core_path System Setting is set to {assets_path}mycomponents/notify/core/components/notify/

    require_once $modx->getOption('nf.core_path', null, $modx->getOption('core_path') . 
        'components/notify/') . 'model/notify/notify.class.php';
    



    There's a similar System Setting, nf.assets_path:

    {assets_path}mycomponents/notify/assets/components/notify/


    and also nf.assets_url (e.g., for injecting CSS and JS):

    {assets_url}mycomponents/notify/assets/components/notify/


    That said, in theory, you could put them anywhere you want by adjusting the paths in the config file, but I don't think it would work very well (if at all -- I think it would confuse the build file unless you modified it, which kind of defeats the purpose of having a universal build file that works for all projects).

    Plus, having absolutely all the project's files under one directory (assets/mycomponents/componentname) makes using Git and working on them a lot easier than if they were in different directories (and I'm not sure where the _build and test directories would go).
      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
      • 37099
      • 338 Posts
      I'm just working through Doodles again but with a different db table structure.

      I'll try and do the same thing from scratch using MyComponent and see how I get along.
        • 3749
        • 24,544 Posts
        Just a note. You can import existing class, snippet, plugin, chunk, CSS, and JS, etc., code files into MyComponent, but it works best if you can start from scratch, put the object names for all the files you'll need in the project's config file, run Bootstrap, and then paste the code into the files. To add new stuff, adjust the config file and run Bootstrap again. That way you'll get consistent license, author, and other PhpDoc stuff in the files. It also makes sure every file you have is referenced in the config file.

        Obviously, this is less practical if you have a ton of files.
          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