Quote from: BobRay at Nov 20, 2014, 03:18 AMYou might find this helpful: http://bobsguides.com/blog.html/2014/03/28/modx-2.2-cmps-an-anatomy-lesson/.
You might also take a look at MyComponent. It comes with an example project that creates a CMP (among other things). You can copy it or just look at it's code to follow along with the article in the link above.
I think there is also a MIGx way of creating CMPs, though I haven't used it.
Thank you for article, I think I solver my problem in a proper way:
So, I created my custom connector and processor.
From my CMP, when user presses "Save" button, it sends AJAX POST request to connector.php, that is placed in /assets/components/my_component_name/ with 'action' parameter and other parameters that I need.
Here is the code of my connector.php:
<?php
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php';
require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
require_once MODX_CONNECTORS_PATH.'index.php';
$corePath = $modx->getOption('my_component_name.core_path',null,$modx->getOption('core_path').'components/my_component_name/');
require_once $corePath.'model/my_component_name.class.php';
$modx->my_component_className= new my_component_className($modx);
/* handle request */
$path = $modx->getOption('processorsPath',$modx->my_component_className->config,$corePath.'processors/');
$modx->request->handleRequest(array(
'processors_path' => $path,
'location' => ''
));
The action parameter is a path to processor relative to path is set in 'processors_path' in $modx->request->handleRequest.
I set action parameter to 'mgr/saveorder' as my processor file is there /core/components/my_component_name/processors/mgr/saveorder.class.php
By the way, as I discovered name of processor MUST be lower-case.
Here is the code of saveorder.class.php:
<?php
class SortArticlesSaveOrderProcessor extends modProcessor {
public function initialize() {
return parent::initialize();
}
public function process() {
$sortOrder = json_decode($this->getProperty('order'));
foreach($sortOrder as $order => $id) {
$page = $this->modx->getObject('modResource', $id);
if (!$page->setTVValue('sort_id', $order)) {
$this->modx->log(xPDO::LOG_LEVEL_ERROR, 'There was a problem saving sort_id in saveorder.class.php');
return 'Ошибка.';
}
}
return 'Изменения успешно сохранены.';
}
}
return 'SortArticlesSaveOrderProcessor';