We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48058
    • 8 Posts
    Hi,
    I am developing an app that uses discuss and i would like to allow my users to create new categories for discuss from the front-end.
    So, i tried to do it using the runProcessor but didn't have any luck.
    here is my code
    $path = 'core/components/discuss/processors';
    $response = $modx->runProcessor('mgr/category/create', array(
        'name' => $catname
    ), array('processors_path' => $path));
    


    Am i missing something, or am i doing something wrong?
    I am using revo 2.2.14
    Thanks in advance
      • 48058
      • 8 Posts
      I also tried this but still no luck

      $corePath = $modx->getOption('discuss.core_path',null,$this->modx->getOption('core_path').'components/discuss/');
      $processorsPath = $corePath.'processors/';
      $response = $modx->runProcessor('mgr/category/create', array(
          'name' => 'TEST CATEGORY'
      ), array('processors_path' => $processorsPath));
        • 48058
        • 8 Posts
        Hm... instead of using the runProcessor I managed to solve this with this code:

        $modx->addPackage('discuss',MODX_CORE_PATH.'components/discuss/model/');
        $category = $modx->newObject('disCategory');
        $category->set('name','TEST');
        $category->save();


        Apparently the object disCategory since it is in a different model folder than modx would search you have to point somehow to the discuss classes that are in the core/components/discuss/model folder somehow and this is done with addPackage.
          • 3749
          • 24,544 Posts
          Good solution! You might try it without the addPackage() call. I think the discuss package is registered in the extension_packages System Setting (I could be wrong). If so, the discuss package would be loaded automatically on every request.
            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
            • 48058
            • 8 Posts
            Tried to use it at first without the addPackage() but no effect.
            Any idea why the runProcessor couldnt run the create category processor?
              • 3749
              • 24,544 Posts
              Are you sure that processor exists? I can't find it.
                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
                • 48058
                • 8 Posts
                Isnt it core/components/discuss/processors/mgr/category/create.php ?
                Looking at the code there surely it can create a category,am i wrong?
                  • 3749
                  • 24,544 Posts
                  Duh. I didn't have Discuss installed. That's why I couldn't find it. wink

                  Yes, the processor should work. I think the problem may have been the missing trailing slash here:

                  $path = 'core/components/discuss/processors/';


                  MODX paths almost always end in a slash.
                    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