Smarty's section loop problem with standard result sets
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PHPDevShell |
Fix Released
|
High
|
TitanKing |
Bug Description
PHPDS_query returns multiple results in a multi-dimensional associative array. The default behaviour is that it uses the primary key of the result set as the indexing for the array. For example, if the result set contains the following data:
ID,Country,City
5,US,New York
6,UK,London
9,SA,Johannesburg
The associative array will look like this:
Array (
[5] => Array (
[id] => 5
[country] => US
[city] => New York )
[6] => Array (
[id] => 6
[country] => UK
[city] => London )
[9] => Array (
[id] => 9
[country] => SA
[city] => Johannesburg )
)
The Smarty {section} loop does not like this type of array as it seems to expect a zero based incremental index for the array. I'm not sure whether this is a bug in Smarty itself or whether it is the standard behaviour. Apparently PHPDS_query can be told not to use the primary key as the index of the array which will solve the problem, however, when one uses the pagination plugin for example, it does not give you access to its underlying PHPDS_query objects and therefore one can not switch it off. The only way around the problem is to use the {foreach}
My suggestion is that:
a) The PHPDS_query class should perhaps by default not use the primary key as the index of the result set array.
b) The Pagination class should allow a developer to specify whether the primary key should be used as the index of the result set array.
c) {foreach} should perhaps be used instead of {section} in all the PHPDS templates. If this change is too much work then we should just confirm wether the {section} issue is indeed an issue or whether it is standard behaviour.
PHPDevShell version: V 3.0.2-Stable-
Browser: Firefox v 4.0.1
OS: Ubuntu 10.04 LTS
Kernel: Linux 2.6.32-28
PHP Version: 5.3.2
MySQL Version: 5.1.41
Apache: 2.2.14
Changed in phpdevshell: | |
status: | New → Confirmed |
assignee: | nobody → TitanKing (titan-phpdevshell) |
Changed in phpdevshell: | |
status: | Confirmed → Fix Committed |
Changed in phpdevshell: | |
status: | Fix Committed → Fix Released |
Although it's a smarty defect, it can easily be fixed by just setting:
protected $keyField = '';
in the query.