Skip to content

Instantly share code, notes, and snippets.

@aisteron
Created January 23, 2019 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aisteron/51c4d4facaf018bc1afa69a1876b8165 to your computer and use it in GitHub Desktop.
Save aisteron/51c4d4facaf018bc1afa69a1876b8165 to your computer and use it in GitHub Desktop.
modx ajax snippet
<?php
/*$page = $modx->getObject('modResource', 13);
$chars = json_decode($page->getTVValue('chars'));
echo '<pre>';
foreach($chars as $k => $v)
{
echo $v->key0.'-'.$v->value0;
}
return;*/
$where = array( 'parent' => 6 );
$resources = $modx->getCollection('modResource',$where);
$cars = [];
foreach ($resources as $k => $res) {
//echo $modx->getObject('modResource', $k)->getTVValue('chars').'<br><br>';
/*$res = $modx->getObject('modResource', $k)->getTVValue('chars');
echo '<pre>';
print_r(json_decode($res));*/
//echo '<pre>';
//print_r($res->get('uri'));
$cars[$k]['uri'] = $res->get('uri');
$cars[$k]['pagetitle'] = $res->get('pagetitle');
$page = $modx->getObject('modResource', $k);
$chars = json_decode($page->getTVValue('chars'));
foreach($chars as $key => $v)
{
//echo $v->key0.'-'.$v->value0;
$cars[$k][$v->key0] = $v->value0;
}
}
//echo '<pre>';
//print_r($cars);
echo json_encode($cars);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment