开发者

Codeigniter directory_map()

开发者 https://www.devze.com 2022-12-26 20:17 出处:网络
I\'m trying to use the directory_map(\'source directory\',false) function to scan through user uploa开发者_开发问答ded folders/files. It works and spit out the result in a multilevel array format.

I'm trying to use the directory_map('source directory',false) function to scan through user uploa开发者_开发问答ded folders/files. It works and spit out the result in a multilevel array format.

I wouldn't know how deep is the multi level array would be. How do I iterate the array and display it in a readable format (e.g. in html (ol/ul) tags)?


Recursive functions, whoop!

Here is an example of a recursive function being used in one of my view files.

            <tbody> 
                <?php function album_row($albums, $parent, $lvl) { ?>
                <?php if(isset($albums[$parent])) foreach ($albums[$parent] as $album): ?>
                    <tr>
                        <td><?php echo form_checkbox('action_to[]', $album->id); ?></td>
                <td><?php echo repeater('-- ', $lvl);?> <?php echo $album->title;?></td>
                <td><?php echo $album->num_photos;?></td>
                <td><?php echo date('M d, Y', $album->updated_on);?></td>
                <td><?php echo anchor('photos/' . $album->slug, lang('photo_albums.view_label'), 'target="_blank"') . ' | ' .
                                anchor('admin/photos/manage/' . $album->id, lang('photo_albums.manage_label')) . ' | ' .
                                anchor('admin/photos/edit/' . $album->id, lang('photo_albums.edit_label')) . ' | ' .
                                anchor('admin/photos/delete/' . $album->id, lang('photo_albums.delete_label'), array('class'=>'confirm')); ?>
                </td>
              </tr>
              <?php album_row($albums, $album->id, $lvl+1) ?>
              <?php endforeach; }?>            
              <?php album_row($albums, 0, 0); ?>
            </tbody>

Yours will be a little different as basically you want to create a function that checks if the content is an array or a string.

If its a string, echo. If its an array, call the same function again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号