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
      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
      • 49407
      • 159 Posts
      Ok I will. Thanks.

      Is all this...
      $prefix = 'xyz_';
      $tablename = 'chronicles';
      $packagename = 'chronicleThis';
      
      $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/');
      $modelpath = $packagepath . 'model/';
      
      $schemapath = $modelpath . 'schema/';
      $schemafile = $schemapath . $packagename . '.mysql.schema.xml';
      $manager = $modx->getManager();
      $generator = $manager->getGenerator();
      $generator->parseSchema($schemafile, $modelpath);
      $modx->addPackage($packagename, $modelpath, $prefix);
      $classname = $generator->getClassName($tablename);

      required just to access the class to make a DB update or insert?
        • 4172
        • 5,888 Posts
        the package needs to be registered somewhere, before you can use its classes and you will need to know the classname.

        then this is enough:

        $prefix = 'xyz_';
        $classname = 'Chronicle';
        $packagename = 'chroniclethis';//should be lowercase
         
        $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/');
        $modelpath = $packagepath . 'model/';
        $modx->addPackage($packagename, $modelpath, $prefix);


        you can also register your package with the system-setting 'extension-packages', if you need to have it registered on every request.

          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 49407
          • 159 Posts
          Quote from: Bruno17 at Dec 12, 2014, 05:52 AM
          the package needs to be registered somewhere, before you can use its classes and you will need to know the classname.

          then this is enough:

          $prefix = 'xyz_';
          $classname = 'Chronicle';
          $packagename = 'chroniclethis';//should be lowercase
           
          $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/');
          $modelpath = $packagepath . 'model/';
          $modx->addPackage($packagename, $modelpath, $prefix);


          you can also register your package with the system-setting 'extension-packages', if you need to have it registered on every request.


          Thank you, Bruno17!

          I kept breaking it by removing lines trying to figure out what I could skin it down to.

          I like to use as little lines of code as possible. Awesome!