PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Structures » Structures_DataGrid » Bug #7925

formatter args ignored in Column->formatter()

Details

Submitted2006-06-16 14:32 UTC
Fromclark at thirteen dot net
Assignedwiesemann
StatusClosed
PackageStructures_DataGrid
PHP Version5.1.2
OSAll
Roadmaps(Not assigned)

Comments

[2006-06-16 14:32 UTC] clark at thirteen dot net

Description:
------------
When you define a new Structures_DataGrid_Column, if you specify arguments to your formatter callback, they do not appear in the function when the function is called.

I have fixed this bug.

From looking at the code, they are parsed and stored, but when formatter() is called, they are never used. So all I did was initialize the paramList to $this->formatterArgs, and it works.

This worked in 0.6.3, so it looks like it was introduced in CVS.

Test script:
---------------
$datagrid =& new Structures_DataGrid();
// $hits is a DB_result set or other valid datasource, containing a column called score$n
$stat = $datagrid->bind($hits);
// db field name is score$n
$datagrid->addColumn(new Structures_DataGrid_Column($n, "score$n", null, null, null, "formatScore(score_num=$n)"));

$datagrid->render();

function formatScore($params)
{
if(is_numeric($params['n'])) {
return('Yes, arg is working');
} else {
return('No, arg not honored');
}

FIX: Replace line 218 in Structures/DataGrid/Column.php with
$paramList = $this->formatterArgs;
(instead of $paramList = array());

WARNING: if the user-supplied params happens to be any of the following: record, fieldName, columnName, orderBy, attribs, we will have a conflict, but that's a different bug!

Expected result:
----------------
Each scoreN cell should say Yes, arg is working.

Actual result:
--------------
Each scoreN cell will say No, arg not honored.

[2006-06-16 19:18 UTC] clark at thirteen dot net

I see: the array of arguments passed in the seventh arg of the Column constructor are actually treated as "first class" args to the formatter function. Whereas before everything was packed into a single array. Is that right?

So I define my function e.g.

function myFormatter($environmentVals, $myArg1, $myArg2)
{
//formatting logic here
}

So I just pass a single-dimension array of values to the Column constructor, and they will automatically be assigned to the 2nd, 3rd and so on args of my formatter?

Sorry, I missed that.