Implement a Zend partialLoop() with jQuery nestedSortables

This is in fact mainly a Zend question than a jQuery.

I’m trying to implement jQuery nested Sortable http://mjsarfatti.com/sandbox/nestedSortable/ with Zend, saving and reading out the exact position of the sortable elements (including their parents). I have now the following code in my partialLoop file which is the main part of my work. It calls itself (recursively) in another partialLoop() method if there are children of an element and looks like the following, which is the partials/_docs-edit-row.phtml itself:

<?php
// not really nice to call a db model in a view file, but is there an other way... ?
$  docSectionModel = new Model_DocSection();
global $  workedthrough, $  i;

$  childs = $  docSectionModel->fetchChildSections($  this->id);
if($  childs)
    $  childs = $  childs->toArray();
?>

<?php if(empty($  workedthrough) || !in_array($  this->id, $  workedthrough)) : ?>
<?php $  workedthrough[] = $  this->id; ?>
<li>
    <div class="handle">
        <input type="hidden" class="section_id" name="section_id[<?php echo $  i; ?>]" value="<?php echo $  this->id; ?>" />
        <input type="hidden" class="section_parent_id" name="section_parent_id[<?php echo $  i; ?>]" value="<?php echo $  this->parent_id; ?>" />
        <input type="text" name="section_title[<?php echo $  i; ?>]" value="<?php echo $  this->title; ?>" />
        <a href="#" class="open"></a>
    </div>
    <div class="inner-edit closed">
        <textarea name="section_content[<?php echo $  i; ?>]"><?php echo $  this->content; ?></textarea>
        <input type="submit" name="doc_save" value="Save" />
        <input type="submit" name="remove_doc_section[<?php echo $  i; ?>]" value="Remove this section" />
    </div>

    <?php if($  childs) : ?>
        <ol>
            <?php echo $  this->partialLoop('partials/_docs-edit-row.phtml', $  childs); ?>
        </ol>
    <?php endif; ?>

</li>
<?php endif; ?>
<?php $  i++; ?>

What I was trying to do here was to create with $ i a counter which goes through both loops to get a continous counter because $ this->partialCounter would start from the beginning in each new level. So in fact this is my main problem (I defined the $ i in the main view file as well as $ workthrough which is to look if the item has been gone over to avoid multiple calls of items which are not in the first level of the loop) that $ i doesn’t seem to count properly for any reason while $ workthrough works like a charm.
Now, is it possible to have a continous counter in all the partialLoops? Also I really would like to know if maybe someone got a better approach to do what I want to do.

If something looks strange or is unclear I will explain it of course. I appreciate any help!

Best Regards, .wired

newest questions tagged jquery – Stack Overflow

About Admin