具有指定resourceID的getResources-Snippet不起作用

时间:2011-01-05 11:33:44

标签: php modx

我有一个名为“Kategorie”的电视,我想要一个由该电视分组的指定资源(27)下的所有资源的列表。没什么特别的imho。这是我的方法:

<?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>';
}
?>

...对我来说看起来不错,但却向我抛出了这个错误:

[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 )

任何人都知道这里发生了什么?或者甚至有更好的方法来实现我的目标?

更新

我更新了最新版本的getResources。现在我没有收到该错误消息。但它不起作用。但“父母”选项也不起作用。

1 个答案:

答案 0 :(得分:1)

我使用的是$modx->getDocument($id),现在按预期工作了。

  foreach($ids as $rid) {
    $doc = $modx->getDocument($rid);
    var_dump($doc);
    // real output trimmed
  }