Skip to content

Instantly share code, notes, and snippets.

@Mark-H
Last active November 4, 2025 13:31
Show Gist options
  • Select an option

  • Save Mark-H/4303088 to your computer and use it in GitHub Desktop.

Select an option

Save Mark-H/4303088 to your computer and use it in GitHub Desktop.
modCli; using MODX on the commandline.
<?php
// include modX
define('MODX_API_MODE', true);
// Full path to the index
require_once('/path/to/modx/public_html/index.php');
$modx= new modX();
$modx->initialize('mgr');
// Get the cli options
$options = array();
$action = $argv[1];
parse_str(implode('&', array_slice($argv, 2)), $options);
// hand over the weaponry
if (empty($action)) {
exit('Missing action!');
}
$result = $modx->runProcessor($action, $options);
$msg = $result->getMessage();
if ($result->isError()) {
exit ('Failed to make you a sandwich: '.$msg);
}
echo 'Done. '.$msg;
exit(0);
@carnevlu
Copy link
Copy Markdown

Hi @Mark-H now that define('MODX_API_MODE', true); is deprecated, how archive the same behaviour without login?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment