We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45490
    • 5 Posts
    Hi,

    I am new to MODx and trying to learn as I build a custom component. I basically need advice on how to get data displayed in a grid from a custom processor.

    My processor currently gets an array of data via web services. Right now, I am stuck at understanding how to build a custom processor without using a database ($classKey) for data. My processor should get data and then send it back to the JavaScript to display in a grid.

    Do I need to format the array of data in JSON in order to have it display in a ExtJS grid? When I try to use
    ->toJSON
    the JSON object is empty. What is the correct formatting the array should be in order to turn it into JSON?

    /processors/mgr/myextra/receive.class.php
    :

    class ReceiveProcessor extends modObjectGetListProcessor{
    
        public function initialize() {
            return parent::initialize();
        }
    
        public function process() {
            $data = $this->getCompleted();
            // $data looks like ->
            // Array( 
            //[1] => Submission Object(   
            //    [name] => Tom
            //    [date] => 12345678
            //    [otherinfo] => Male
            //    ...
    	//) ...
    
            //$list = $this->iterate($data);
            //$output = $this->toJSON($list);
            //return $this->outputArray($list,$data['total']);
    
            return '';
        }
    


    JS Example:
    receive.grid.js

    MyExtra.grid.Receive = function(config) {
        config = config || {};
        this.sm = new Ext.grid.CheckboxSelectionModel();
        Ext.applyIf(config,{
            id: 'myextra-grid-receive'
            ,url: MyExtra.config.connectorUrl
            ,baseParams: { action: 'mgr/myextra/receive' }
            ,fields: ['id','name','date','otherinfo']
            ...
    

    [ed. note: dnelson last edited this post 12 years, 11 months ago.]
      • 3749
      • 24,544 Posts
      You don't need the toJSON() call. $this->outputArray() will convert it to JSON for you.
        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
        • 45490
        • 5 Posts
        Thanks BobRay. I got it working. Sleeping helped.

        I have one more question. Is there an easier way to debug than posting this in every function I want to investigate?

        $modx = new modX();
        $modx->log(modX::LOG_LEVEL_DEBUG, $data);
        [ed. note: dnelson last edited this post 12 years, 11 months ago.]
          • 3749
          • 24,544 Posts
          I use a chunk called debug and add this function to the top of my code:

          if (! function_exists('my_debug'));
              function my_debug($message, $clear = false) {
                  /* @var $chunk modChunk */
                  $chunk = $modx->getObject('modChunk', array('name' => 'debug'));
          
                  if (!$chunk) {
                      $chunk = $modx->newObject('modChunk', array('name' => 'debug'));
                      $chunk->save();
                      $chunk = $modx->getObject('modChunk', array('name' => 'debug'));
                  }
                  if ($clear) {
                     $content = '';
                  } else {
                      $content = $chunk->getContent();
                  }
                     $content .= $message;
                     $chunk->setContent($content);
                     $chunk->save();
                  }
              }
          }



          my_debug('Some Message') will append the output to the chunk's current content. my_debug('Some Message', true) will clear the chunk and write the new message to it.

          That way you can use Quick Update Chunk to see the output without leaving your place in the Manager.

          If you create the chunk manually, you can leave out the code that creates 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