
abstract class ExampleManagerController extends modExtraManagerController {
/** @var Example $example */
public $example = NULL;
/* Initialize the main manager controller.*/
public function initialize() {
/* Instantiate the Example class in the controller */
$path = $this->modx->getOption('example.core_path',
NULL, $this->modx->getOption('core_path') .
'components/example/') . 'model/example/';
require_once $path . 'example.class.php';
$this->example = new Example($this->modx);
/* Optional alternative - install PHP class as a service */
/* $this->example = $this->modx->getService('example',
'Example', $path);*/
/* Add the main javascript class and our configuration */
$this->addJavascript($this->example->config['jsUrl'] .
'example.class.js');
$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
Example.config = ' . $this->modx->toJSON($this->example->config) . ';
});
</script>');
}
public function getLanguageTopics() {
return array('example:default');
}
public function checkPermissions() {
return true;
}
public function getTemplateFile() {
return $this->example->config['templatesPath'] . 'mgr.tpl';
}
}
/**
* The Index Manager Controller is the default one that gets
* called when no action is present. */
class IndexManagerController extends ExampleManagerController {
/* Defines the name or path to the default controller to load. */
public static function getDefaultController() {
return 'home';
}
}[28-Oct-2014 13:21:44 UTC] PHP Fatal error: Class 'ExampleIndexManagerController' not found in /Volumes/Sites/cmp/core/model/modx/modmanagerresponse.class.php on line 185
$action = $modx->newObject('modAction');
$action->fromArray( array (
'namespace' => 'example',
'controller' => 'index',
'haslayout' => 1,
'lang_topics' => 'example:default',
'assets' => '',
'help_url' => '',
'id' => 1,
), '', true, true);
$menus[1] = $modx->newObject('modMenu');
$menus[1]->fromArray( array (
'text' => 'Example',
'parent' => 'components',
'description' => 'ex_menu_desc',
'icon' => '',
'menuindex' => 0,
'params' => '',
'handler' => '',
'permissions' => '',
'id' => 1,
), '', true, true);
$menus[1]->addOne($action);
The bottom line is that if the menu 'action' field has a number, there has to be a modAction record with that ID, but if it's a string naming the action, the modAction is unnecessary -- at least that's my guess.
class IndexManagerController extends ExampleManagerController {
/* Defines the name or path to the default controller to load. */
public static function getDefaultController() {
return 'home';
}
}Does your index.class.php file have something like this at the end?
class IndexManagerController extends ExampleManagerController { /* Defines the name or path to the default controller to load. */ public static function getDefaultController() { return 'home'; } }
<?php
/**
* The abstract Manager Controller.
* In this class, we define stuff we want on all of our controllers.
*/
abstract class MyextraManagerController extends modExtraManagerController {
/**
* Initializes the main manager controller. You may want to load certain classes,
* assets that are shared across all controllers or configuration.
*
* All your other controllers in this namespace should extend this one.
*
* In this case we don't do anything useful, but as you build up more complex
* extras, it helps to enforce this structure to make it easier to maintain.
*/
public function initialize() {
$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
// We could run some javascript here that runs on all of our controllers
// for example something that loads your config
});
</script>');
}
/**
* Defines the lexicon topics to load in our controller.
* @return array
*/
public function getLanguageTopics() {
return array('namespace:default');
}
/**
* We can use this to check if the user has permission to see this controller
* @return bool
*/
public function checkPermissions() {
return true;
}
}
/**
* The Index Manager Controller is the default one that gets called when no
* &action parameter is passed We use it to define the default controller
* which will then handle the actual processing.
*
* It is important to name this class "IndexManagerController" and making sure
* it extends the abstract class we defined above
*/
class IndexManagerController extends MyextraManagerController {
/**
* Defines the name or path to the default controller to load.
* @return string
*/
public static function getDefaultController() { return 'home'; }
}
<?php
/**
* The name of the controller is based on the action (home) and the
* namespace. This home controller is loaded by default because of
* our IndexManagerController.
*/
class MyextraHomeManagerController extends MyextraManagerController {
/**
* Any specific processing we want to do here. Return a string of html.
* @param array $scriptProperties
*/
public function process(array $scriptProperties = array()) {
return '<h2 class="modx-page-header">It\'s alive!</h2><p>This is your first custom manager page. You are awesome!</p>';
}
/**
* The pagetitle to put in the <title> attribute.
* @return null|string
*/
public function getPageTitle() {
return 'My first CMP!';
}
/**
* Register needed assets. Using this method, it will automagically
* combine and compress them if that is enabled in system settings.
*/
public function loadCustomCssJs() {
$this->addCss('url/to/some/css_file.css');
$this->addJavascript('url/to/some/javascript.js');
$this->addLastJavascript('url/to/some/javascript_load_last.js');
$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
// We could run some javascript here
});
</script>');
}
}

I don't know why that wouldn't work. Mark Hamstra could probably tell us.Yeah, i'll see if I can pick his brains on this. If all else fails i'll add in manual actions into the modx_actions table as I guess that table will be there for a while still.