mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- bugfix {foreach} did fail if from atrribute is a Generator class https://github.com/smarty-php/smarty/issues/128
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
===== 3.1.29-dev ===== (xx.xx.2015)
|
||||
16.12.2015
|
||||
- bugfix {foreach} did fail if from atrribute is a Generator class https://github.com/smarty-php/smarty/issues/128
|
||||
|
||||
15.12.2015
|
||||
- bugfix {$smarty.cookies.foo} did return the $_COOKIE array not the 'foo' value https://github.com/smarty-php/smarty/issues/122
|
||||
- bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828)
|
||||
|
@@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.29-dev/5';
|
||||
const SMARTY_VERSION = '3.1.29-dev/6';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -183,8 +183,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
foreach ($saveVars as $k => $code) {
|
||||
$output .= "{$local}{$k} = {$code}\n";
|
||||
}
|
||||
$output .= "{$itemVar} = new Smarty_Variable();\n";
|
||||
if (isset($itemAttr['show']) || isset($itemAttr['total']) || isset($namedAttr['total']) || isset($namedAttr['show']) || isset($itemAttr['last']) || isset($namedAttr['last'])) {
|
||||
$output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
|
||||
}
|
||||
$output .= "{$itemVar} = new Smarty_Variable();\n";
|
||||
if (isset($itemAttr['show'])) {
|
||||
$output .= "{$itemVar}->show = ({$local}total > 0);\n";
|
||||
}
|
||||
@@ -210,7 +212,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
$output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n";
|
||||
}
|
||||
}
|
||||
$output .= "if ({$local}total) {\n";
|
||||
if (isset($attributes['key'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n";
|
||||
}
|
||||
@@ -226,7 +227,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
if ($needIteration) {
|
||||
$output .= "{$local}iteration=0;\n";
|
||||
}
|
||||
$output .= "{$itemVar}->_loop = false;\n";
|
||||
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
|
||||
$output .= "{$itemVar}->_loop = true;\n";
|
||||
if (isset($attributes['key']) && isset($itemAttr['key'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
|
||||
}
|
||||
@@ -296,7 +299,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
|
||||
$output = "<?php\n";
|
||||
$output .= "{$itemVar} = {$local}saved_local_item;\n";
|
||||
$output .= "}\n";
|
||||
$output .= "} else {\n?>";
|
||||
$output .= "if (!{$itemVar}->_loop) {\n?>";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -332,7 +335,6 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
|
||||
|
||||
if ($restore) {
|
||||
$output .= "{$itemVar} = {$local}saved_local_item;\n";
|
||||
$output .= "}\n";
|
||||
}
|
||||
$output .= "}\n";
|
||||
foreach ($restoreVars as $restore) {
|
||||
|
@@ -27,6 +27,9 @@ class Smarty_Internal_Runtime_Foreach
|
||||
// thus rewind() and valid() methods may not be present
|
||||
return iterator_count($value->getIterator());
|
||||
} elseif ($value instanceof Iterator) {
|
||||
if ($value instanceof Generator) {
|
||||
return 1;
|
||||
}
|
||||
return iterator_count($value);
|
||||
} elseif ($value instanceof PDOStatement) {
|
||||
return $value->rowCount();
|
||||
|
Reference in New Issue
Block a user