Smarty's section loop problem with standard result sets

Bug #781565 reported by Don Schoeman
8
This bug affects 1 person
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}/{foreachelse} Smarty loop instead of {section}/{sectionelse}. The problem for plugin developers is that since all of the PHPDS Smarty templates uses {section}, they would probably also tend to use it and will then run into the same problem.

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-DB-3001 (Revision-bzr 678)
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

Revision history for this message
Greg (gregfr) wrote :

Although it's a smarty defect, it can easily be fixed by just setting:

 protected $keyField = '';

in the query.

Revision history for this message
Don Schoeman (don.sch) wrote :

The problem is that pagination class does not give the developer access to the keyField property. The pagination class itself is derived from PHPDS_dependant and not from PHPDS_query so one don't have access to that field. It will have to be added.

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
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.