← Back to team overview

phpdevshell team mailing list archive

[Bug 781565] Re: Smarty's section loop problem with standard result sets

 

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


	protected $keyField = '';

in the query.

-- 
You received this bug notification because you are a member of
PHPDevShell, which is subscribed to PHPDevShell.
https://bugs.launchpad.net/bugs/781565

Title:
  Smarty's section loop problem with standard result sets

Status in Open Source PHP RAD Framework with UI.:
  New

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


References