PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Structures » Structures_DataGrid » Bug #4046

Use an object to define a "more intuitive" column formatter?

Details

Request #4046Use an object to define a "more intuitive" column formatter?
Submitted2005-04-04 04:50 UTC
Fromdaniel at assertio dot es
StatusBogus
PackageStructures_DataGrid
PHP Version5.0.2
OSWin XP
Roadmaps(Not assigned)

Comments

[2005-04-04 04:50 UTC] daniel at assertio dot es

Description:
------------
Hello,
I was trying to set the column callback to a non-static method function (as in bug report 3089) from within a class method, for example:

// this code is inside a class method
$formatter = "\$this->formatListField(\$fieldName = '$fieldname')";
$dg->addColumn(new Structures_DataGrid_Column( $field['label'], $fieldname, $sortAttributes, $cellAttributtes, null, $formatter));

But when it comes to is_callable statement in column.php (line 192), it won't pass.

Why not, as you mention in the method comments, use an object instead of a string to define de callback and parameters ? Something like:

$formatter = new Structures_DataGrid_ColumnFormatter( 'functionName', array('param1' => $param1), &$this);

$dg->addColumn(new Structures_DataGrid_Column( $field['label'], $fieldname, $sortAttributes, $cellAttributtes, null, $formatter));

Reproduce code:
---------------
I made a very simple class to archive this, you may see it at http://www.quintopino.com/pear/ColumnFormatter.phps

Modifications are required in Column.php: 4 lines added in line 163. You may also check them at http://www.quintopino.com/pear/Column.phps
Current functionality is preserved.

[2005-04-07 08:38 UTC] daniel at assertio dot es

I'm not sure I'm getting it correctly. You mean something like:

// this code is inside a class method
$obj = $this;
$formatter = "class::formatListField(\$fieldName =
'$fieldname', \$object = $obj)";
$dg->addColumn(new Structures_DataGrid_Column( $field['label'],
$fieldname, $sortAttributes, $cellAttributtes, null, $formatter));

Anyway, thanks for your reply, as you point I'll use a class that extends the column class.