<?php // Set this to your MODx Base Path $base_path = '/var/www/modx/'; define('MODX_API_MODE', true); include($base_path.'index.php'); $modx->db->connect(); $modx->getSettings();
This solution is for standalone pages/requests wanting to access MODx resources (Ajax Calls, External CMSs, etc.).

<?php
define('MODX_API_MODE', true); if (defined('MODX_API_MODE')) { echo 'modx.php | MODX_API_MODE | TRUE <br />' . "\n"; }
include 'modx.class.php';
$test = new MODx;
$test -> printMODx();
echo 'modx.php | test <br />' . "\n";
echo print_r($test) . '<br />' . "\n";
?>
<?php
class MODx {
var $modx;
function printMODx() {
echo 'modx.class.php | MODX_API_MODE | '; if (defined('MODX_API_MODE')) { echo 'TRUE <br />' . "\n"; }
echo 'modx.class.php | modx <br />' . "\n";
echo print_r($this -> modx) . '<br />' . "\n";
} // END function printMODx
function getMODx() {
include '/home/xxx/www/index.php';
$this -> modx -> db -> connect();
$this -> modx -> getSettings();
} // END function getMODx
} // END class MODx
?>
modx.php | MODX_API_MODE | TRUE modx.class.php | MODX_API_MODE | TRUE modx.class.php | modx 1 modx.php | test MODx Object ( [modx] => ) 1
[Sat May 10 15:02:38 2008] [error] [client xxx.xxx.xxx.xxx] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/www/bkupmodx/modx.php:6) in /home/xxx/www/index.php on line 59 [Sat May 10 15:02:38 2008] [error] [client xxx.xxx.xxx.xxx] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/www/bkupmodx/modx.php:6) in /home/xxx/www/index.php on line 60 [Sat May 10 15:02:38 2008] [error] [client xxx.xxx.xxx.xxx] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/xxx/www/bkupmodx/modx.php:6) in /home/xxx/www/manager/includes/config.inc.php on line 59 [Sat May 10 15:02:38 2008] [error] [client xxx.xxx.xxx.xxx] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/www/bkupmodx/modx.php:6) in /home/xxx/www/manager/includes/config.inc.php on line 73 [Sat May 10 15:02:38 2008] [error] [client xxx.xxx.xxx.xxx] PHP Warning: DocumentParser::include_once(/home/xxx/www/manager/includes/extenders/dbapi..class.inc.php) [<a href='documentparser.include-once'>documentparser.include-once</a>]: failed to open stream: No such file or directory in /home/xxx/www/manager/includes/document.parser.class.inc.php on line 39 [Sat May 10 15:02:38 2008] [error] [client xxx.xxx.xxx.xxx] PHP Warning: DocumentParser::include_once() [<a href='function.include'>function.include</a>]: Failed opening '/home/xxx/www/manager/includes/extenders/dbapi..class.inc.php' for inclusion (include_path='.:/usr/lib/php') in /home/xxx/www/manager/includes/document.parser.class.inc.php on line 39
<?php
class myObject {
var $modx;
function myObject(&$modx) {
$this->modx = $modx;
}
}
<?php
// Set this to your MODx Base Path
$base_path = '/var/www/modx/';
define('MODX_API_MODE', true);
include_once($base_path.'index.php');
$modx->db->connect();
$modx->getSettings();
// create myObject class
include_once($base_path.'<path_to_object>/myObject.class.php');
$myObject = new myObject($modx);
Hope that helps,
Garry
include_once($base_path.'index.php'); $modx->db->connect(); $modx->getSettings();