Structures_DataGrid::bind()

Structures_DataGrid::bind() -- Binds a data type that is supported by a DataSource Driver to the DataGrid

概要

mixed bind (mixed $data)

説明

This method allows you to bind your data set to the DataGrid. You can bind any data type that is supported with a DataSource driver. If you have a data type that is not supported, you can easily create your own driver by mimicing the parent class or one of the existing drivers or post a message to the mailing lists to see if someone can help you with it. If you write your own, please post it back to the community for anyone else who might be interested in using it.

パラメータ

mixed $data

The record set in any of the supported data source types (i.e. DB_DataObject, DB_Result, XML, RSS, CSV, Array)

array $options

Optional. An array of options to be used, these are respective to the driver.

string $type

Optional. This is used if the data source type cannot be detected.

返り値

mixed - TRUE upon success otherwise a PEAR_Error upon failure

例 54-1Bind datagrid to a DB_DataObject


<?php
$dg =& new Structures_DataGrid(20);
      
$person = new DataObjects_Person;

$person->hair = 'red';
$person->has_glasses = 1; 

// The datagrid will bind the dataobject and only select the first 20 records
$dg->bind($person);

$dg->render();
?>

例 54-2Bind datagrid to a DB_Result Object with DataGrid paging


<?php
$dg =& new Structures_DataGrid(20);
      
$result = $db->query("SELECT * FROM person WHERE hair='red' AND has_glasses=1");

// The datagrid will bind the db_result object and only show the first 20 records
// This is not the most optimal way, because the datagrid will load all of the
// records and then limit down to 20, but will allow for paging.
$dg->bind($result);

$dg->render();
?>

例 54-3Bind datagrid to a DB_Result Object with Database paging


<?php
$dg =& new Structures_DataGrid();
      
$result = $db->query("SELECT * FROM person WHERE hair='red' AND has_glasses=1 LIMIT 20");

// The datagrid will bind the db_result object and show all of the first 20 records
// In order to use paging, you must use a seperate Pager object.
$dg->bind($result);

$dg->render();
?>