We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37743
    • 49 Posts
    I'm working on a custom component that will display data pulled from an external source via a PHP api. As such, i dont have an xPDO model for it.

    How on earth do I go about getting it plugged into connectors/processors so i can display it in a modExt-grid? Can I just return a json string at a certain point along the route?
      • 4172
      • 5,888 Posts
      In your getList - processor you can define your own process-function.
      With some code like that:

      <?php
      
          public function process() {
             
              $limit = intval($this->getProperty('limit'));
              $start = intval($this->getProperty('start'));
              $sort = $this->getProperty('sort');
              $dir = $this->getProperty('dir'); 
              
              if ($data_array = $yourApi->getData($start,$limit,$sort,$dir)){
                  $total = $yourApi->getTotal;  
              }
               else{
                  return $this->failure('Error');
              }           
      
              return $this->outputArray($data_array,$total);
          }
      


      See also the doodles-example:
      http://rtfm.modx.com/display/revolution20/Developing+an+Extra+in+MODX+Revolution%2C+Part+II
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37743
        • 49 Posts
        Thanks Bruno, that should get me on my way...

        Brick wall hit though when I load my processor, modx is picking up the class name returned, but then errors with class not defined?!

        <?php
        class McmCampaignGetListProcessor extends modObjectGetListProcessor {
            public $languageTopics = array('mcm:default');
            public $defaultSortField = 'last_sent';
            public $defaultSortDirection = 'DESC';
            public $classKey = 'MCMCampaign';
            public $objectType = 'mcm.campaign';
            
        public function initialize(){
        		return parent::initialize(); 
        	}//
        
        
        public function process() {
                
                $limit = intval($this->getProperty('limit'));
                $start = intval($this->getProperty('start'));
                $sort = $this->getProperty('sort');
                $dir = $this->getProperty('dir'); 
                 
                if ($data_array = $yourApi->getData($start,$limit,$sort,$dir)){
                    $total = $yourApi->getTotal;  
                }
                 else{
                    return $this->failure('Error');
                }           
         
                return $this->outputArray($data_array,$total);
            }//
        		
        };// end class McmCampaignGetListProcessor
        return 'McmCampaignGetListProcessor';


        If I change the return value, the error reflects it, so the file is clearly being loaded, but for some reason it cant find the class that is declared directly above?!

        EDIT: And just to head-off any repurcussions... yes i am aware that my process function is guff... just for example... [ed. note: alanpich last edited this post 14 years, 5 months ago.]
          • 28215
          • 4,149 Posts
          You need to either:

          a) load the package using $modx->addPackage in the your overridden initialize method
          b) load the package through the "extension_packages" system setting
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 37743
            • 49 Posts
            thats the one! many thanks Shaun (and Bruno for getting me there)