![]() |
|
sfN1IterationPlugin - 0.1.5Easily edit iterations N1. |
|
The sfN1IterationPlugin makes easy the edition of simple iterations of a table with N-1 relations.
./symfony plugin-install http://plugins.symfony-project.com/sfN1IterationPlugin
<?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>
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.
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.