function __construct(modX &$modx, array $config = array()) { $this->modx =& $modx; $corePath = $this->modx->getOption('myAddon.core_path',null,$modx->getOption('core_path').'components/myAddon/'); $assetsUrl = $this->modx->getOption('myAddon.assets_url', null, $this->modx->getOption('assets_url').'components/myAddon/'); $this->modx->lexicon->load('myAddon:default'); $this->config = array_merge(array( 'corePath' => $corePath, 'modelPath' => $corePath.'model/', 'managerPath' => $corePath.'manager/', 'controllersPath' => $corePath.'controllers/', 'templatesPath' => $corePath.'templates/', 'baseUrl' => $assetsUrl, 'cssUrl' => $assetsUrl.'css/', 'jsUrl' => $assetsUrl.'js/', ),$config); }
require_once dirname(dirname(dirname(__FILE__))) . '/model/myAddon/myAddon.class.php'; class MyAddonIndexManagerController extends modExtraManagerController { /** @var MyAddon $myAddon */ public $myAddon; public function initialize() { $this->myAddon = new MyAddon($this->modx); $this->addCss($this->myAddon->config['cssUrl'].'mgr.css'); $this->addJavascript($this->myAddon->config['jsUrl'].'mgr/myAddon.js'); $this->addHtml('<script type="text/javascript"> Ext.onReady(function() { MyAddon.config = '.$this->modx->toJSON($this->myAddon->config).'; }); </script>'); return parent::initialize(); } public function getLanguageTopics() { return array('myAddon:default'); } public function checkPermissions() { return true;} public function process(array $scriptProperties = array()) {} public function getPageTitle() { return $this->modx->lexicon('myAddon'); } public function loadCustomCssJs() { $this->addJavascript($this->myAddon->config['jsUrl'].'mgr/widgets/myAddon.grid.js'); $this->addJavascript($this->myAddon->config['jsUrl'].'mgr/widgets/home.panel.js'); $this->addLastJavascript($this->myAddon->config['jsUrl'].'mgr/sections/index.js'); } public function getTemplateFile() { return $this->myAddon->config['templatesPath'].'home.tpl'; } }
http:/mysite.com/manager/mgr/filename.js
MyAddon.config = '.$this->modx->toJSON($this->myAddon->config).';
This question has been answered by multiple community members. See the first response.
Hmm, works for me.
Is your index.class.php file in the controllers directory?
Glad you got it working but it shouldn't need to be in a default directory.
The index.class.php controller shown in the Doodles tutorial will work fine if it's just located in the /core/components/doodles/controllers/ directory. If you set your menu action to index (or whatever you've named your file) it'll find it.
Make sure you don't have an index.php file one level up in your doodles directory though (an older way of doing it).
Can you retrieve your external rest data by overriding the getlist processor? Some of the comments touch on that at http://www.hkwebdeveloper.com/modext-tutorial-series-part-2.html
<?php class EventGetListProcessor extends modObjectGetListProcessor { public function outputEvents(array $output, $count = false) { /* not sure this is required here */ $path = $modx->getOption('ebents.core_path',NULL, $modx->getOption('core_path') .'components/ebents/') . 'model/ebents/'; require_once $path . 'ebents.class.php'; // calls to main class functions to retrieve events $mgr_client = new Ebents($modx); $params = array (); $params['expand'] = 'venue,organizer'; $args = array('id' => 'me', 'data' => 'owned_events', 'params' => $params); $output = $mgr_client->getData('users', $args); $count = count($output->events); //error_log("count :" . $count); $msg = ($count>0)?"OK":NULL; print '{"total":"'.$count.'","results":'.$modx->toJSON($output->events).',"success":true,"msg":"'.$msg.'"}'; //error_log(print_r($output,true)); } } return 'EventGetListProcessor';
... Ext.extend(Ebents.panel.Home,MODx.Panel, { checkValue: function() { MODx.Ajax.request({ url: Ebents.config.connectorUrl , params: { action: 'mgr/events/getEvents' } , listeners: { success: { fn: function (response) { console.log('The value returned from the processor is: '+response.msg); if(response.msg == "OK") { this.loadGrid(); } }, scope: this } } }); },loadGrid: function() { var ebentsGrid = MODx.load({ xtype: 'ebents-grid-ebents' ,cls: 'main-wrapper' ,preventRender: true ,flex: 1 }); var tab = Ext.getCmp('main-tab'); tab.add(ebentsGrid); this.doLayout(); } }); ...
<?php class GetEventsProcessor extends modProcessor { public $output = array(); public $count; public $msg; public function process() { // calls to main class functions to retrieve events $this->mgr_client = new Ebents($modx); $this->params = array (); $this->params['expand'] = 'venue,organizer'; $this->args = array('id' => 'me', 'data' => 'owned_events', 'params' => $this->params); $this->output = $this->mgr_client->getData('users', $this->args); $this->count = count($this->output->events); //error_log("count :" . $this->count); $this->msg = ($this->count > 0)?"OK":NULL; return '{"total":"'.$this->count.'","results":'.$modx->toJSON($this->output->events).',"success":true,"msg":"'.$this->msg.'"}'; //error_log(print_r($this->output,true)); } } return 'GetEventsProcessor';
PHP Fatal error: Call to a member function getOption() on null in /paas/c0059/www/core/components/ebents/model/ebents/ebents.class.php on line 14
Only looking at this from my phone but can you try passing $this->modx instead of just $modx to your class?
EDIT:
At a computer now.
From inside a processor, you need to access it via $this->modx instead of just $modx like you might in a snippet.
Uncaught TypeError: b[(d.xtype || e)] is not a function
Ebents.panel.Home = function(config) { config = config || {}; Ext.apply(config,{ border: false ,baseCls: 'modx-formpanel' ,cls: 'container' ,items: [{ html: '<h2>'+_('debents.management')+'</h2>' ,border: false ,cls: 'modx-page-header' },{ xtype: 'modx-tabs' ,defaults: { border: false ,autoHeight: true } ,border: true ,items: [{ title: _('ebents.panel_1_header') ,defaults: { autoHeight: true } ,items: [{ html: '<p>'+_('ebents.management_desc')+'</p>' ,border: false ,bodyCssClass: 'panel-desc' },{ xtype: 'ebents-grid-ebents' ,cls: 'main-wrapper' ,preventRender: true }] }] // only to redo the grid layout after the content is rendered // to fix overflow components' panels, especially when scroll bar is shown up ,listeners: { 'afterrender': function(tabPanel) { tabPanel.doLayout(); } } }] }); Ebents.panel.Home.superclass.constructor.call(this,config); }; Ext.extend(Ebents.panel.Home,MODx.Panel); Ext.reg('ebents-panel-home',Ebents.panel.Home);
Ebents.grid.Ebents = function(config) { config = config || {}; Ext.applyIf(config,{ id: 'ebents-grid-events' ,url: Ebents.config.connectorUrl ,baseParams: { action: 'mgr/event/getList' } ,fields: ['id','name->text','description->text','organizer->name','venue->name','start->local','end->local','status'] //<- should field refs be in JSON dot notation or array? And if so, where is it converted to array (or where should it be)? ,trackMouseOver:true ,disableSelection:true ,loadMask: true ,paging: true ,remoteSort: true ,anchor: '97%' ,columns: [{ header: _('ebents.event_id') ,dataIndex: 'id' ,sortable: true ,width: 70 },{ header: _('ebents.event_name') ,dataIndex: 'name->text'//<- nested data in array form but where is this converted from JSON to array if so? ,sortable: true ,width: 150 ,editor: { xtype: 'textfield' } },{ header: _('ebents.event_description') ,dataIndex: 'description->text' ,sortable: false ,width: 250 ,editor: { xtype: 'textfield' } },{ header: _('ebents.event_organizer') ,dataIndex: 'organizer->name' ,sortable: true ,width: 80 ,editor: { xtype: 'textfield' } },{ header: _('ebents.event_venue') ,dataIndex: 'venue->name' ,sortable: true ,width: 80 ,editor: { xtype: 'textfield' } },{ header: _('ebents.event_start') ,dataIndex: 'start->local' ,sortable: true ,width: 80 ,editor: { xtype: 'textfield' } },{ header: _('ebents.event_end') ,dataIndex: 'end->local' ,sortable: true ,width: 80 ,editor: { xtype: 'textfield' } },{ header: _('ebents.event_status') ,dataIndex: 'status' ,sortable: true ,width: 80 ,editor: { xtype: 'textfield' } } ] }); Ebents.grid.Ebents.superclass.constructor.call(this,config) }; Ext.extend(Ebents.grid.Ebents,MODx.grid.Grid); Ext.reg('ebents-grid-events',Ebents.grid.Ebents);
<?php class GetEventsProcessor extends modProcessor { public $output = array(); public $count; public $msg; public $modx; public function process() { $this->mgr_client = new Ebents($this->modx); $this->params = array (); $this->params['expand'] = 'venue,organizer'; $this->args = array('id' => 'me', 'data' => 'owned_events', 'params' => $this->params); $this->output = $this->mgr_client->getData('users', $this->args); $this->count = count($this->output->events); //error_log("count :" . $this->count); return '{"total":"'.$this->count.'","results":'.$this->modx->toJSON($this->output->events).',"success":true}'; //error_log(print_r($this->output->events,true)); } } return 'GetEventsProcessor';