Permalink
Browse files

(Fixes issue 556) A new approach to save CPU time.

  • Loading branch information...
1 parent b7432e0 commit 89a77866b39eab032dcbdef50c65f2842d432f1f istvan.beregszaszi committed Sep 4, 2009
Showing with 15 additions and 12 deletions.
  1. +5 −5 docs/guide/form.table.txt
  2. +6 −0 docs/guide/upgrade.txt
  3. +4 −7 framework/web/helpers/CHtml.php
View
@@ -48,10 +48,10 @@ display the input fields in an HTML table.
<tr><th>Name</th><th>Price</th><th>Count</th><th>Description</th></tr>
<?php foreach($items as $i=>$item): ?>
<tr>
-<td><?php echo CHtml::activeTextField($item,"name[$i]"); ?></td>
-<td><?php echo CHtml::activeTextField($item,"price[$i]"); ?></td>
-<td><?php echo CHtml::activeTextField($item,"count[$i]"); ?></td>
-<td><?php echo CHtml::activeTextArea($item,"description[$i]"); ?></td>
+<td><?php echo CHtml::activeTextField($item,"[$i]name"); ?></td>
+<td><?php echo CHtml::activeTextField($item,"[$i]price"); ?></td>
+<td><?php echo CHtml::activeTextField($item,"[$i]count"); ?></td>
+<td><?php echo CHtml::activeTextArea($item,"[$i]description"); ?></td>
</tr>
<?php endforeach; ?>
</table>
@@ -61,7 +61,7 @@ display the input fields in an HTML table.
</div><!-- yiiForm -->
~~~
-Note in the above that we use `"name[$i]"` instead of `"name"` as the
+Note in the above that we use `"[$i]name"` instead of `"name"` as the
second parameter when calling [CHtml::activeTextField].
If there is anything validation error, the corresponding input fields will
View
@@ -45,3 +45,9 @@ Changes Related with Table Alias in Relational Active Record
relation name. Previously in version 1.0.x, by default Yii would automatically
generate a table alias for each relational table, and we had to use the prefix
`??.` to refer to this automatically generated alias.
+
+Changes Related with Tabular Input
+----------------------------------
+
+- For attribute names, using Field[$i] is not valid anymore, they should look
+like [$i]Field in order to support array-typed fields (e.g. [$i]Field[$index]).
@@ -1767,14 +1767,11 @@ public static function resolveNameID($model,&$attribute,&$htmlOptions)
*/
public static function resolveName($model,&$attribute)
{
- if(preg_match('#(\[(\w+)\])?(\w+)(\[(\w+)\])?#', $attribute, $matches))
- {
- $attribute=$matches[3];
- unset($matches[0], $matches[1], $matches[4]); // remove full pattern and indexes with brackets
- return get_class($model).'['.implode('][', array_filter($matches)).']';
- }
+ if('['===$attribute[0])
+ list($i, $attribute, $index)=array(strtok($attribute, '[]'), strtok('['), strtok(']'));
else
- return get_class($model).'['.$attribute.']';
+ list($attribute, $index)=array(strtok($attribute, '['), strtok(']'));
+ return get_class($model).(isset($i) ? '['.$i.']' : '').'['.$attribute.']'.(false!==$index ? '['.$index.']' : '');
}
/**

0 comments on commit 89a7786

Please sign in to comment.