We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50923
    • 137 Posts
    Can somebody describe what is proper way to insert custom class in MODx, where to insert

    class Foo {
    public function Hello{
    ....
    }
    }


    Where to call it, and how to use it, i saw there is xPDO and GetClass, but what is common way. And also is ti possible to get in class like this


    $modx->Foo->new Foo();


    Not like
    $Foo = new Foo();


    Is there some advantage of first solution?
    How to pass VAR from Chunk to class Foo but to method Hello();

    Txanks, i hope someone will make good example, because for now all i see is documentation, but there is no good simple example;0
      <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
      • 3749
      • 24,544 Posts
        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
        • 50923
        • 137 Posts
        Quote from: BobRay at Aug 18, 2015, 11:49 AM
        See if this helps: http://bobsguides.com/custom-db-tables.html

        I asked as someone knows to help me make a simple example, this is doc also and much complex, I just wanted to see simple proper example, after that i will make my own class
          <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
          • 3749
          • 24,544 Posts
          The reason for the complexity is that most of us want our classes to work with xPDO. Once you've done that, you can load them anywhere with this:


          $modx->loadClass('Foo');
          $Foo = $modx->newObject('Foo');
          


          You can also make them constantly available by registering them as extension packages. Then they will be loaded on every page request.

          If you just want something really simple:

          include "path/to/class/foo.class.php";
          $Foo = new Foo();
            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