cvs: peardoc /fr/package/structures/structures-datagrid examples.xml

From: Date: Sun, 17 Oct 2004 20:36:21 +0000
Subject: cvs: peardoc /fr/package/structures/structures-datagrid examples.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-4986@lists.php.net to get a copy of this message
moosh Sun Oct 17 16:36:21 2004 EDT Added files: /peardoc/fr/package/structures/structures-datagrid examples.xml Log: inital translation http://cvs.php.net/co.php/peardoc/fr/package/structures/structures-datagrid/examples.xml?r=1.1&p=1 Index: peardoc/fr/package/structures/structures-datagrid/examples.xml +++ peardoc/fr/package/structures/structures-datagrid/examples.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.1 Maintainer: moosh Status: started --> <refentry id="package.structures.structures-datagrid.examples"> <refnamediv> <refname>Exemples</refname> <refpurpose> Utilisation de <classname>Structures_DataGrid</classname> </refpurpose> </refnamediv> <refsect1> <title>Création d'une grille</title> <para> Le premier exemple crée une grille simple à partir d'un tableau PHP de données d'entrée. </para> <example> <title>Grille simple avec des données d'entrée statiques</title> <programlisting role="php"> <![CDATA[ require_once "Structures/DataGrid.php"; $rs = array(array('id' => 1, 'first_name' => 'Bob', 'last_name' => 'Smith', 'age' => '37'), array('id' => 2, 'first_name' => 'John', 'last_name' => 'Doe', 'age' => '23'), array('id' => 3, 'first_name' => 'Fred', 'last_name' => 'Thompson', 'age' => '58'), array('id' => 4, 'first_name' => 'Sally', 'last_name' => 'Robinson', 'age' => '52'), array('id' => 5, 'first_name' => 'Robert', 'last_name' => 'Brown', 'age' => '19')); $dg = new Structures_DataGrid; $dg->bind($rs); // Afficher la grille de données $dg->render(); ]]> </programlisting> </example> <para> La table dans l'exemple ci-dessus est assez moche, mais il y a des méthodes simples pour changer son look et son feeling. </para> <para> L'exemple suivant génère une table de XHTML qui contient tous les pays en Europe. Le classement peut être changé et la table est fractionnée en pages simples avec 15 pays par page. Le style de la table est ajusté en utilisant quelques attributs de formatage de table et un peu de <acronym>CSS</acronym>. Contrairement à l'exemple précédent, les données ont été tirées d'une base de données de <acronym>SQL</acronym>. </para> <example> <title>Grille avec la pagination, tri et des données dynamiques</title> <programlisting role="php"> <![CDATA[ ?> <html> <head> <title>DataGrid: Example</title> <style type="text/css"> table.datagrid {font-family: Verdana, Arial; font-size: x-small; background-color: #333333;} </style> </head> <body> <?php require_once "DB.php"; require_once "Structures/DataGrid.php"; $dbh = DB::Connect("mysql://world@localhost/world"); $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $query = "SELECT Name, Continent FROM Country WHERE Continent = 'Europe'"; $sth = $dbh->query($query); if (isset($_GET['page'])) { $dg = new Structures_DataGrid(15, $_GET['page']); } else { $dg = new Structures_DataGrid(15); } // Define DataGrid Color Attributes $dg->renderer->setTableHeaderAttributes(array('bgcolor' => '#3399FF')); $dg->renderer->setTableOddRowAttributes(array('bgcolor' => '#CCCCCC')); $dg->renderer->setTableEvenRowAttributes(array('bgcolor' => '#EEEEEE')); // Définition des Attributs du Tableau de la grille de données $dg->renderer->setTableAttribute('width', '50%'); $dg->renderer->setTableAttribute('cellspacing', '1'); $dg->renderer->setTableAttribute('cellpadding', '4'); $dg->renderer->setTableAttribute('class', 'datagrid'); // Set empty row table attributes $dg->renderer->allowEmptyRows(true, array('bgcolor' => '#FFFFFF')); // Define columns for the DataGrid $column = new Structures_DataGrid_Column('Name', 'Name', 'Name', array('width' => '75%')); $dg->addColumn($column); $column = new Structures_DataGrid_Column('Continent', 'Continent', 'Continent', array('width' => '75%')); $dg->addColumn($column); // Add rows to the DataGrid while ($sth->fetchInto($row)) { $row = new Structures_DataGrid_Record($row); $result = $dg->addRecord($row); if (PEAR::isError($result)) { echo $result->getMessage(); } } // Sort the array based on the field if (isset($_GET['orderBy'])) { $dg->sortRecordSet($_GET['orderBy'], $_GET['direction']); } else { $dg->sortRecordSet('Name'); } // Afficher la grille de données $dg->render(); echo $dg->renderer->getPaging(); ?> </body> </html> <?php ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->

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