cvs: peardoc /en/package/structures/structures-datagrid faq.xml formatter.xml

From: Date: Sun, 01 Oct 2006 14:15:22 +0000
Subject: cvs: peardoc /en/package/structures/structures-datagrid faq.xml formatter.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-8553@lists.php.net to get a copy of this message
wiesemann Sun Oct 1 14:15:22 2006 UTC Modified files: /peardoc/en/package/structures/structures-datagrid faq.xml formatter.xml Log: - remove new FAQ entry from yesterday - sync example code from this FAQ entry to the existing example in formatter.xml - make the example more readable http://cvs.php.net/viewvc.cgi/peardoc/en/package/structures/structures-datagrid/faq.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/structures/structures-datagrid/faq.xml diff -u peardoc/en/package/structures/structures-datagrid/faq.xml:1.2 peardoc/en/package/structures/structures-datagrid/faq.xml:1.3 --- peardoc/en/package/structures/structures-datagrid/faq.xml:1.2 Sat Sep 30 07:50:06 2006 +++ peardoc/en/package/structures/structures-datagrid/faq.xml Sun Oct 1 14:15:21 2006 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <refentry id="package.structures.structures-datagrid.faq"> <refnamediv> <refname>FAQ</refname> @@ -146,40 +146,6 @@ <qandaentry> <question> <para> - How do I use the formatter with my own arguments? - </para> - </question> - <answer> - <para> - The following example shows a printDesc function which appends '...' to - a string if the length exceeds the given size. This size can be specified - for every column differently via an array element with the key 'length' - as the last parameter of the column constructor. -<programlisting role="php"> -<![CDATA[ -// example column, relevant for this example are only the last two parameters -$datagrid->addColumn(new Structures_DataGrid_Column('Description', 'description', - 'description', null, null, 'printDesc', array('length' => 15))); - -function printDesc($params, $args) -{ - extract($params); - extract($args); - - if (strlen($record[$fieldName]) > $length) { - return nl2br(substr($record[$fieldName], 0, $length)) . '...'; - } else { - return nl2br($record[$fieldName]); - } -} -]]> -</programlisting> - </para> - </answer> - </qandaentry> - <qandaentry> - <question> - <para> I'm using the Excel Renderer and would like to have the &euro; sign in the resulting Excel file, but I always get only a box or some funny characters. How can I get the right &euro; sign? http://cvs.php.net/viewvc.cgi/peardoc/en/package/structures/structures-datagrid/formatter.xml?r1=1.5&r2=1.6&diff_format=u Index: peardoc/en/package/structures/structures-datagrid/formatter.xml diff -u peardoc/en/package/structures/structures-datagrid/formatter.xml:1.5 peardoc/en/package/structures/structures-datagrid/formatter.xml:1.6 --- peardoc/en/package/structures/structures-datagrid/formatter.xml:1.5 Sun Apr 23 21:52:27 2006 +++ peardoc/en/package/structures/structures-datagrid/formatter.xml Sun Oct 1 14:15:21 2006 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <refentry id="package.structures.structures-datagrid.formatter"> <refnamediv> <refname>Column Formatter</refname> @@ -28,25 +28,38 @@ die('An error occured while fetching the RSS information.'); } -$dg->addColumn(new Structures_DataGrid_Column('Release', 'title', 'title', null, null, 'printLink()')); -$dg->addColumn(new Structures_DataGrid_Column('Description', 'description', 'description', null, null, 'printDesc($length=150)')); -$dg->addColumn(new Structures_DataGrid_Column('Date', 'dc:date', 'dc:date')); +$dg->addColumn( + new Structures_DataGrid_Column('Release', 'title', 'title', + null, null, 'printLink') +); +$dg->addColumn( + new Structures_DataGrid_Column('Description', 'description', + 'description', null, null, + 'printDesc', array('length' => 15)) +); +$dg->addColumn( + new Structures_DataGrid_Column('Date', 'dc:date', 'dc:date') +); $dg->render(); -function printLink($params) +function printLink($params, $args) { extract($params); + extract($args); + return '<a href="' . $record['link'] . '">' . $record['title'] . '</a>'; } -function printDesc($params) +function printDesc($params, $args) { - extract ($params); - if (strlen($record['description']) > $length) { - return nl2br(substr($record['description'], 0, $length)) . '...'; + extract($params); + extract($args); + + if (strlen($record[$fieldName]) > $length) { + return nl2br(substr($record[$fieldName], 0, $length)) . '...'; } else { - return nl2br($record['description']); - } + return nl2br($record[$fieldName]); + } } ?> ]]>

« previous php.pear.doc (#8553) next »