Question

I have a TV named "Kategorie" and I want a list of all resources underneath a specified resource (27) grouped by this TV. Nothing special imho. This is my approach:

<?php
$resource_ids = $modx->getTree(27,1); # => 27 is the Container with the desired resources
# We need the 'Kategorie'-TV of the resources
$cat = $modx->getObject('modTemplateVar', array('name' => 'Kategorie'));

# Map Resources to Category
$resources_by_cat = array();
foreach ($resource_ids as $id) { 
  $resources_by_cat[$cat->getValue($id)][] = $id; 
}

# Iterate over categories and output the resources
foreach ($resources_by_cat as $cat => $ids) {
  $joined_ids = join(",",$ids); # => eg "33,34,56"
  print "<h2>".$cat."</h2>";
  print '<table class="references">';
  print '
    <tr>
      <th class="title">Titel</th>
      <th class="author">Von</th>
    </tr>
    ';
  print $modx->runSnippet('getResources', array(
    "resources" => $joined_ids,
    "includeTVs" => "1",
    "tpl" => "referenceRow"
  ));
  print '</table>';
}
?>

… which looks fine to me but throws this error to me:

[2011-01-05 12:26:24] (ERROR @ /index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1,2,15,18,27,23,30,3,4,22,24,26,47,5,6,7,8,9,10,11,12,14,13,17,16,19,20,49,50,21' at line 1 )

Anyone knows what's going on here? Or is there even a better approach to my goal?

UPDATE

I updated to the most recent version of getResources. Now I don't get that error message. Yet it does not work. But the "parents" option does not work either.

Was it helpful?

Solution

I used $modx->getDocument($id) instead and it works now as expected.

  foreach($ids as $rid) {
    $doc = $modx->getDocument($rid);
    var_dump($doc);
    // real output trimmed
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top