We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44234
    • 219 Posts
    Hoping someone could help with an issue I've got with a cmp processor and explain a little about how they work.

    I have followed this tutorial: https://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/developing-an-extra-in-modx-revolution/developing-an-extra-in-modx-revolution,-part-ii and everything seems to be working except the processor which will populate the my grid.

    My grid widget:
    Hibp.grid.tab = function(config) {
      config = config || {};
      Ext.applyIf(config,{
        id: 'hibp-grid-tab'
        ,url: Hibp.config.connectorUrl // the php connector file which point to the php processors
        ,baseParams: { action: 'getlist.class' } // the php processor file to run and populate the grid
        ,fields: ['id','name','desc'] // add the fields we'll get from the AJAX request
        ,paging: true // add pagination
        ,remoteSort: true // allow columns to be sortable
        ,columns: [{
          header: 'ID'
          ,dataIndex: 'id'
          ,sortable: true
          ,width: 60
        },{
          header: 'Name'
          ,dataIndex: 'name'
          ,sortable: true
          ,width: 100
        },{
          header: 'Description'
          ,dataIndex: 'desc'
          ,sortable: false
          ,width: 350
        }]
      });
      Hibp.grid.tab.superclass.constructor.call(this,config)
    };
    Ext.extend(Hibp.grid.tab,MODx.grid.Grid); // change to MODx.grid.Grid
    Ext.reg('hibp-grid-tab',Hibp.grid.tab); //register this component to its xtype
    

    And my processor as documented in above tut (at this point I'm just just trying get a simple array into the grid):
    class HibpGetUserProcessor extends modProcessor { //modObjectGetListProcessor
      public function process() {
        $count = 1;
        $array = array(
          "id" => "8310024813",
          "name" => "Joe Organizer",
          "desc" => "Joe is the Organizerest Organizer."
        );
        return $this->outputArray($array,$count);
      }
    }
    return 'HibpGetUserProcessor';
    

    With this processor I get this error in the console 'ReferenceError: HibpGetUserProcessor is not defined' and the grid is empty. I inspected what is being returned and it is literally returning the class name 'HibpGetUserProcessor', no data.

    If I remove the class then data is returned and the grid populates correctly:
    $count = 1;
    $array = array(
      "id" => "8310024813",
      "name" => "Joe Organizer",
      "desc" => "Joe is the Organizerest Organizer."
    );
    $output = $this->outputArray($array,$count);
    
    return $output;
    


    Is anyone able to explain why the first processor example is not working and also why the tutorial recommends using a class in the first place? What is the advantage?

    Many Thanks

    This question has been answered by markh. See the first response.

      Find me on Twitter, GitHub or Google+
    • discuss.answer
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      In your javascript it is requesting the "getlist.class" action - that should just be "getlist".

      MODX tries to load the .class.php file automatically if you pass "getlist", and it will then use the class based processor based on the returned class name. If it can't find a .class.php, it will try with just .php which is the old 2.1-and-earlier way processors were built with direct output from the processor file.

      So you request "getlist.class" which then checks if "getlist.class.class.php" exists as a class based processor. That doesn't exist, so it also looks for "getlist.class.php" which does exist, however that is treated as an old 2.1 style processor, taking the direct output of the file.

      One other thing to note is that you will likely need to change this:

          $array = array(
            "id" => "8310024813",
            "name" => "Joe Organizer",
            "desc" => "Joe is the Organizerest Organizer."
          );
          return $this->outputArray($array,$count);
      


      to something like this:
          $items = array();
          $items[] = array(
            "id" => "8310024813",
            "name" => "Joe Organizer",
            "desc" => "Joe is the Organizerest Organizer."
          );
          return $this->outputArray($items,$count);
      


      as the grid expects an array of arrays, and not just a single array.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 44234
        • 219 Posts
        Thank you Mark!

        Don't surpose you know if there is a list and docs of modx classes that you can extend from the processor do you? Such as 'modProcessor', 'modObjectGetListProcessor' etc
          Find me on Twitter, GitHub or Google+