Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created April 19, 2012 19:38
Show Gist options
  • Save chucktrukk/2423607 to your computer and use it in GitHub Desktop.
Save chucktrukk/2423607 to your computer and use it in GitHub Desktop.
Load and instantiate MODxAPi from a directory
<?php
if( !isset($modx) ) {
/*Test the realpath by just starting with /../ and keep adding till you get where you're going*/
$modx_base_path = realpath(dirname(__FILE__) . '/../../../../../');
define('MODX_BASE_PATH', $modx_base_path.'/' );
$old_dir = getcwd();
chdir(MODX_BASE_PATH);
require MODX_BASE_PATH . 'manager/includes/config.inc.php';
require MODX_BASE_PATH . 'manager/includes/document.parser.class.inc.php';
require MODX_BASE_PATH . 'MODxAPI.class.php';
$modx = new MODxAPI;
$modx->connect();
chdir($old_dir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment