Copyright (c) 2007 Enrique MartÃnez (Markhaus)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfN1IterationPlugin plugin
The sfN1IterationPlugin makes easy the edition of simple iterations of a table with N-1 relations.
Installation
./symfony plugin-install http://plugins.symfony-project.com/sfN1IterationPlugin
Usage
<?php use_helper('N1Iteration') ?>
<?php echo N1iteration($partial, $className, $vars, $iteratorSuffix); ?>
$partial is the partial to be iterated.
$className is the class name of the object iterated.
$vars the same array as usually used in the partials. The first item of this array must be the objects iterated.
$iteratorSuffix an optional suffix for the iterator name.
The partial must have an html tag with the string %id% in the id property, the helper will replace this with an
unique identifier for every iteration. For example:
<div id="%id%">
<!--here your code -->
</div>
Javascript helpers
The plugin provides some simple javascript helpers to use in the partial:
N1Iteration.Insertion.After('%id%') for insert a iteration after this one.
N1Iteration.Insertion.Before('%id%') for insert before.
N1Iteration.Remove('%id%') for remove the iteration.
An example
Let's see an example with the example data model of chapter 14:

The purpose is to easily edit all the comments of an article, in the same page of the article's edition page.
You can have this template to edit an article:
<?php
echo form_tag('article/save');
echo input_tag('title', $article->getTitle());
echo input_tag('content', $article->getContent());
echo N1Iteration('iterationComment', 'Comment', 'comment' => $article->getComments());
echo submit_tag('Save');
?>
And the partial (named _iterationComment) for the iteration:
<div id="%id%">
<?php
echo input_tag('author[]', $comment->getAuthor());
echo input_tag('content[]', $comment->getComment());
echo button_to_function('Add comment', "N1Iteration.Insertion.After('%id%')");
echo button_to_function('Remove comment', "N1Iteration.Remove('%id%')");
?>
</div>
Note: the names of inputs must have the [], so you can get them as arrays later in the action.
You can add, remove or edit easily the comments related to the article.
Changelog
Version 0.1.4-beta
- Minor changes, and fixed a little bug.
Version 0.1.3-beta
- Added N1IterationToolkit.class.php with a method to easily save related objects.
Version 0.1.2-beta
- Added an optional parameter (iteratorSuffix) to the helper, to deal with various iterators.
Version 0.1.1-beta
- Renamed the function in helper to avoid confusion.
Version 0.1.0-beta