1

I have this snippet :

<?php
$list = $modx->runSnippet('getResources', array(
'parents'=>'16',
'depth'=>'1',
'includeContent'=>'1',
'limit'=>'1'
));

$output = explode(',', $list);
//print_r($list);

foreach($output as $i) {
  //echo $i;
  foreach($i as $key => $value) {
    echo $key.' : '.$value.'<br />';
  }
}

With print_r I can see the array ;-)

But using the foreach loop... nothing print !

Thanks for your help...

Chris
  • 435
  • 1
  • 8
  • 21

1 Answers1

2

The problem might be that you are calling 'explode' on an array when it should be taking a string.

Not sure exactly what your $list array looks like, but perhaps try this instead:

foreach ($list as $i) {
  foreach ($i as $key => $value) {
    echo $key.' : '.$value.'<br />';
  }
}

EDIT Have tested this and $list is not an array but a pre-formatted string meant for debugging:

<pre>Array
    (
    [tpl] => 
    [tplOdd] => 
    [tplFirst] => 
...
</pre>

I'm not sure exactly what you want to achieve, but it's usually better to use the tpl parameter to format results using a Chunk.

getResources is designed for listing Resources for front end display and is not generally used to retrieve raw data.

okyanet
  • 3,106
  • 1
  • 22
  • 16
  • Thanks for your reply but I already tried and it does not work – Chris Dec 17 '11 at 17:11
  • Thanks. I understand now why I cannot loop with foreach ;-) In fact I want to format the result of the GetResources with a Snippet and save it in a .txt file – Chris Dec 18 '11 at 08:18
  • No problem :) Just set up your chunk to format your data how you want it and you can then manipulate it in the snippet. It will be output as a string though, just bear that in mind. If you found my answer helpful, please mark it as 'accepted'. Thanks. – okyanet Dec 18 '11 at 21:05
  • Can you help me with a small example. What I need to do is to use `$list = $modx->runSnippet('getResources', array( 'parents'=>'16', 'depth'=>'1', 'includeContent'=>'1' ));` and in my Snippet to use **feedcreator.class.php** to save the feed as test.rss – Chris Dec 19 '11 at 09:59
  • Hey Chris, I think you are making things difficult for yourself - there's a good tute on how to do this without any custom coding required: http://rtfm.modx.com/display/ADDON/getResources.Building+a+RSS+feed – okyanet Dec 21 '11 at 14:40