Last active
November 4, 2025 13:31
-
-
Save Mark-H/4303088 to your computer and use it in GitHub Desktop.
modCli; using MODX on the commandline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Mark-H now that
define('MODX_API_MODE', true);is deprecated, how archive the same behaviour without login?