Modx Evolution (CMS) Integration solution to share
Assumes phpgrid folder installed in a root folder of modx site - e.g. at the same level as the assets/ and manager/ folders
Thanks, Ian!
if (!defined('MODX_BASE_PATH')) { // It is an ajax request directed to phpgrid data.php so get db config and session via modx config file
require_once('../manager/includes/config.inc.php');
startCMSSession(); // start the session withthe same session name and modx used
define('PHPGRID_DB_HOSTNAME',$database_server); // database host name
define('PHPGRID_DB_USERNAME', $database_user); // database user name
define('PHPGRID_DB_PASSWORD', $database_password); // database password
define('PHPGRID_DB_NAME',trim($dbase,'`')); // database name
define('PHPGRID_DB_TYPE', 'mysql'); // database type
define('PHPGRID_DB_CHARSET',$database_connection_charset); // ex: utf8(for mysql),AL32UTF8 (for oracle), leave blank to use the default charset
} else { // accessing phpgrid from within modx
define('PHPGRID_DB_HOSTNAME',$modx->db->config['host']); // database host name
define('PHPGRID_DB_USERNAME', $modx->db->config['user']); // database user name
define('PHPGRID_DB_PASSWORD', $modx->db->config['pass']); // database password
define('PHPGRID_DB_NAME',trim($modx->db->config['dbase'],'`')); // database name
define('PHPGRID_DB_TYPE', 'mysql'); // database type
define('PHPGRID_DB_CHARSET',$modx->db->config['charset']); // ex: utf8(for mysql),AL32UTF8 (for oracle), leave blank to use the default charset
}