cvs: peardoc /en/packages/database db_dataobject.xml
| From: | Alan Knowles | Date: | Thu, 15 Aug 2002 05:38:58 +0000 |
| Subject: | cvs: peardoc /en/packages/database db_dataobject.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5751@lists.php.net to get a copy of this message | ||
alan_k Thu Aug 15 01:38:58 2002 EDT
Modified files:
/peardoc/en/packages/database db_dataobject.xml
Log:
added extra documenation for validate, debug, autoloading and changed linking stuff
Index: peardoc/en/packages/database/db_dataobject.xml diff -u peardoc/en/packages/database/db_dataobject.xml:1.1 peardoc/en/packages/database/db_dataobject.xml:1.2 --- peardoc/en/packages/database/db_dataobject.xml:1.1 Fri Jul 12 00:25:24 2002 +++ peardoc/en/packages/database/db_dataobject.xml Thu Aug 15 01:38:57 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <reference id="packages.database.db-dataobject"> <title>Database DataObjects : SQL Builder and Data Modeling Layer</title> <titleabbrev>DB_DataObject</titleabbrev> @@ -44,7 +44,7 @@ <title>Typical usage example for <classname>PEAR::DB_DataObject</classname></title> <programlisting role="php"> <![CDATA[ - <? + // initialize the DataObject Manager require_once('PEAR.php'); @@ -61,7 +61,7 @@ echo $person->name; -?> + ]]> </programlisting> </example> @@ -91,14 +91,14 @@ <programlisting role="php"> <![CDATA[ - <? + $person = new DataObjects_Person; $person->get(12); $person->name = 'Fred'; $person->update(); -?> + ]]> </programlisting> @@ -110,7 +110,7 @@ </para> <programlisting role="php"> <![CDATA[ -<? + require_once 'DB/DataObject.php'; class DataObjects_Person extends DB_DataObject { @@ -123,7 +123,7 @@ return $members; } } -?> + ]]> </programlisting> @@ -184,13 +184,13 @@ <example> <title> Setting the default options</title> <programlisting role="php"><![CDATA[ -<?php + $config = parse_ini_file('example.ini',TRUE); foreach($config as $class=>$values) { $options = &PEAR::getStaticProperty($class,'options'); $options = $values; } -?> + ]]> </programlisting> </example> @@ -287,7 +287,18 @@ </listitem> </varlistentry> - + <varlistentry> + <term> + <parameter>production</parameter> + <type>boolean</type> + </term> + <listitem> + <para> + if the production option is set, then debugging is totally disabled, this is done to increase + performance. + </para> + </listitem> + </varlistentry> </variablelist> </refsect1> @@ -507,7 +518,7 @@ <programlisting role="php"><![CDATA[ - <? + /* * Table Definition for group */ @@ -538,7 +549,7 @@ /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE } -?>]]> +]]> </programlisting> </example> </para> @@ -633,11 +644,11 @@ <example> <title> Simple fetch of data based on Primary Key</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); print_r($person); -?> + ]]> </programlisting> </example> @@ -660,11 +671,11 @@ <example> <title> Simple fetch of data based on Key and Value</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get('email','test@example.com'); print_r($person); -?> + ]]> </programlisting> </example> @@ -722,10 +733,10 @@ <example> <title> Simple fetch of data based on Primary Key</title> <programlisting role="php"><![CDATA[ -<? + $person = DataObjects_Person::staticGet(12); print_r($person); -?> + ]]> </programlisting> </example> @@ -737,10 +748,10 @@ <example> <title> Simple fetch of data based on Primary Key</title> <programlisting role="php"><![CDATA[ -<? + $person = DB_DataObject::staticGet('DataObjects_Person',12); print_r($person); -?> + ]]> </programlisting> </example> @@ -769,12 +780,12 @@ <example> <title> Simple find of data based on Object Vars</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->hair = 'red'; $person->has_glasses = 1; $number_of_rows = $person->find(); -?> + ]]> </programlisting> </example> @@ -813,7 +824,7 @@ <example> <title> Simple find and fetch of data based on Object Vars</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->hair = 'red'; @@ -826,7 +837,7 @@ $people[] = $person; echo "GOT {$person->name}<BR>"; } -?> + ]]> </programlisting> </example> @@ -927,12 +938,12 @@ <example> <title> Simple fetch and update</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $person->name='fred'; $person->update(); -?> + ]]> </programlisting> </example> @@ -956,12 +967,12 @@ <example> <title> Simple fetch and updated</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->removed=1; $person->whereAdd('age > 21'); $person->update(); -?> + ]]> </programlisting> </example> @@ -1002,11 +1013,11 @@ <example> <title> Simple insert </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->name='fred'; $id = $person->insert(); -?> + ]]> </programlisting> </example> @@ -1047,7 +1058,7 @@ <title> Simple Delete </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $person->delete(); @@ -1058,7 +1069,7 @@ $person->delete(TRUE); -?> + ]]> </programlisting> </example> @@ -1144,14 +1155,14 @@ <example> <title> raw Queries on the database </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->query("select * from {$this->__table} where id > 12"); while ($person->fetch()) { echo $person->name; } -?> + ]]> </programlisting> </example> @@ -1177,7 +1188,7 @@ <example> <title> Adding select statements</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->selectAdd(); $person->selectAdd('id,name'); @@ -1193,7 +1204,7 @@ -?> + ]]> </programlisting> </example> @@ -1240,7 +1251,7 @@ <example> <title> Adding Where Statements</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->whereAdd('age > 12'); $person->whereAdd('age < 30'); @@ -1258,7 +1269,7 @@ echo "$person->id} {$person->name}<BR>"; } -?> + ]]> </programlisting> </example> @@ -1307,7 +1318,7 @@ <example> <title> Setting the Limit</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->limit(2); $person->find(); @@ -1326,7 +1337,7 @@ -?> + ]]> </programlisting> </example> @@ -1374,14 +1385,14 @@ <example> <title> setting the order by</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->orderBy('name'); $person->orderBy('age, eye'); $person->find(); -?> + ]]> </programlisting> </example> @@ -1422,14 +1433,14 @@ <example> <title> Setting the Group by </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->groupBy('name'); $person->groupBy('age, eye'); $person->find(); -?> + ]]> </programlisting> </example> @@ -1519,7 +1530,7 @@ will always attempt to find primary keys that match the value of field, the getLinks() methods will auto load the related object into $object->_tablename_anything </para> - + <para> The other way of using getLink() is to use it with the second parameter which is the table name of the related table, it will then query the primary key on that table to see if it matches the value of the requested row. @@ -1529,12 +1540,39 @@ </refsect1> - - - - - - + + <refsect1> + <title>Using link ini files for table links</title> + <para> + DB_DataObject Version 0.3 introduced the ability to create link ini files so you can map rows to other database + columns using an ini file this ini file should have the name databasename.links.ini, and be placed in the + same folder as the databasename.ini file that is created automatically by createTables.php + </para> + <para> + The Ini file contains a section for each table, then the row that is linked equal to the table and row + that it should locate the row from. + <example> + <title> An example databasename.links.ini file</title> + <programlisting role="ini"><![CDATA[ + +; for table person +[person] +; link value of eycolor to table colors, match name column +eyecolor = colors:name +; link value of owner to table grp, match id column +owner = grp:id +; link value of picture to table attachments, match id column +picture = attachments:id + + + ]]> + </programlisting> + </example> + </para> + </refsect1> + + + <refsect1> <title>::getLink()</title> <para> @@ -1552,14 +1590,14 @@ <example> <title> Getting the related object </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $group = $person->getLink('group_owner'); echo $group->name; $group = $person->getLink('colourid','hair'); -?> + ]]> </programlisting> </example> @@ -1664,13 +1702,13 @@ <example> <title> Loading all the related objects </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(1079); $person->getLinks(); print_r($person); -?> + ]]> </programlisting> </example> @@ -1801,7 +1839,7 @@ <!-- ****************************************** -AutoForm Utilities and Debugging +AutoForm Utilities Validation and Autoloading ******************************************* @@ -1812,9 +1850,9 @@ <refentry id="packages.database.db-dataobject.utils"> <refnamediv> - <refname>AutoForm Utilities and Debugging</refname> + <refname>Auto Form Utilities, Validation, Autoloading </refname> <refpurpose> - ::setFrom(), ::debugLevel() + ::setFrom(), ::validate(), and DB_DataObject::staticAutoLoad() </refpurpose> </refnamediv> @@ -1836,7 +1874,7 @@ <example> <title> Copying data from post or object</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $person->setFrom($_POST['input']); @@ -1854,7 +1892,7 @@ $person->update(); -?> + ]]> </programlisting> </example> @@ -1866,10 +1904,147 @@ </para> + </refsect1> + + + + + <refsect1> + <title>::validate()</title> + <para> + Either validates data as Integers or strings, otherwise calls user defined validation methods + </para> + <funcsynopsis> + <funcprototype> + <funcdef>(mixed boolean or array)<function>::validate</function></funcdef> + <paramdef><parameter></parameter></paramdef> + </funcprototype> + </funcsynopsis> + <para> + check all the objects variables to see if they are valid, by default this means is a column an integer + or string, if you define methods like validateEmail(), in your extended class then it will be called to + validate that rows data. + </para> + <para> + Note: that this validation depends on the PEAR validation package + + <example> + <title>validate usage</title> + <programlisting role="php"><![CDATA[ + +$person = new DataObjects_Person; +$person->get(12); +$person->setFrom($_POST['input']); +$val = $person->validate(); +if ($val === TRUE) { + $person->update(); +} else { + foreach ($val as $k=>$v) { + if ($v) { + echo "there was something wrong with ($k)"; + } + } +} + + + + ]]> + </programlisting> + </example> + + + </para> + <para> + + To add a validation routine to your extended class you should create a method with the name, ValidateXXXXXXX + where XXXXX is the name of the row to validate. + <example> + <title>validate methods</title> + <programlisting role="php"><![CDATA[ +/* inside class DataObject_Person */ +function validateEmail() { + return Validate::email($this->email, true); +} + +function validateHomepage() { + return Validate::url($this->homepage, true); +} +function validateDate() { + return Validate::date($this->date, "%d-%m-%Y", array(01,01,1970), array(01,01,2030)); +} + + ]]> + </programlisting> + </example> + Refer to the Validation package for more details on Validation methods. + + </para> </refsect1> + + + + <refsect1> + <title>::staticAutoloadTable()</title> + <para> + automatically load (include a DataObject class) + </para> + <funcsynopsis> + <funcprototype> + <funcdef>string classname<function>::staticAutoLoadTable</function></funcdef> + <paramdef>string <parameter>tablename</parameter></paramdef> + </funcprototype> + </funcsynopsis> + <para> + based on the config file, automatically includes the class definition for a table + and returns the class name + <example> + <title> Auto loading a tables class </title> + <programlisting role="php"><![CDATA[ + +$personclass = DB_DataObject::staticAutoloadTable('person'); +if (!$personclass) { + echo "NO PERSON TABLE exists.."; + exit; +} + +$person = new $personclass +$person->get(12); + + + ]]> + </programlisting> + </example> + </para> + </refsect1> - + + + + + + + + + </refentry> + <!-- + +****************************************** + Debugging + +******************************************* + +--> + + <refentry id="packages.database.db-dataobject.debugging"> + <refnamediv> + <refname>Debugging</refname> + <refpurpose> + DB_DataObject::debugLevel() ::debug() + </refpurpose> + </refnamediv> + + <refsect1> <title>DB_DataObject::debugLevel()</title> @@ -1888,7 +2063,7 @@ <example> <title> Setting the debugging level </title> <programlisting role="php"><![CDATA[ -<? + // turn debugging high DB_DataObject::debugLevel(5); $person = new DataObjects_Person; @@ -1899,7 +2074,7 @@ DB_DataObject::debugLevel(); -?> + ]]> </programlisting> </example> @@ -1909,6 +2084,48 @@ </refsect1> + <refsect1> + <title>DB_DataObject::debug()</title> + <para> + using the built in debug output of DB_DataObject + </para> + <funcsynopsis> + <funcprototype> + <funcdef><function>DB_DataObject::debug</function></funcdef> + <paramdef>string <parameter><optional>message</optional></parameter></paramdef> + <paramdef>string<parameter><optional>subject</optional></parameter></paramdef> + <paramdef>int <parameter><optional>debug level</optional></parameter></paramdef> + </funcprototype> + </funcsynopsis> + <para> + Outputs data to the screen, to show you what is happening in the application. + </para> + <para> + Note that in production mode, the debugger is disabled. + <example> + <title> Setting the debugging level </title> + <programlisting role="php"><![CDATA[ + + +$person = new DataObjects_Person; +$person->get(12); + +// always prints +$person->debug('just got the person, about to set stuff', 'my application',0); +$person->setFrom($_POST['input']); + +// only prints if debuglevel is set +$person->debug('just set the variables, about to update', 'my application',1); +$person->update(); + + + ]]> + </programlisting> + </example> + + + </para> + </refsect1> </refentry>
Index: peardoc/en/packages/database/db_dataobject.xml diff -u peardoc/en/packages/database/db_dataobject.xml:1.1 peardoc/en/packages/database/db_dataobject.xml:1.2 --- peardoc/en/packages/database/db_dataobject.xml:1.1 Fri Jul 12 00:25:24 2002 +++ peardoc/en/packages/database/db_dataobject.xml Thu Aug 15 01:38:57 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <reference id="packages.database.db-dataobject"> <title>Database DataObjects : SQL Builder and Data Modeling Layer</title> <titleabbrev>DB_DataObject</titleabbrev> @@ -44,7 +44,7 @@ <title>Typical usage example for <classname>PEAR::DB_DataObject</classname></title> <programlisting role="php"> <![CDATA[ - <? + // initialize the DataObject Manager require_once('PEAR.php'); @@ -61,7 +61,7 @@ echo $person->name; -?> + ]]> </programlisting> </example> @@ -91,14 +91,14 @@ <programlisting role="php"> <![CDATA[ - <? + $person = new DataObjects_Person; $person->get(12); $person->name = 'Fred'; $person->update(); -?> + ]]> </programlisting> @@ -110,7 +110,7 @@ </para> <programlisting role="php"> <![CDATA[ -<? + require_once 'DB/DataObject.php'; class DataObjects_Person extends DB_DataObject { @@ -123,7 +123,7 @@ return $members; } } -?> + ]]> </programlisting> @@ -184,13 +184,13 @@ <example> <title> Setting the default options</title> <programlisting role="php"><![CDATA[ -<?php + $config = parse_ini_file('example.ini',TRUE); foreach($config as $class=>$values) { $options = &PEAR::getStaticProperty($class,'options'); $options = $values; } -?> + ]]> </programlisting> </example> @@ -287,7 +287,18 @@ </listitem> </varlistentry> - + <varlistentry> + <term> + <parameter>production</parameter> + <type>boolean</type> + </term> + <listitem> + <para> + if the production option is set, then debugging is totally disabled, this is done to increase + performance. + </para> + </listitem> + </varlistentry> </variablelist> </refsect1> @@ -507,7 +518,7 @@ <programlisting role="php"><![CDATA[ - <? + /* * Table Definition for group */ @@ -538,7 +549,7 @@ /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE } -?>]]> +]]> </programlisting> </example> </para> @@ -633,11 +644,11 @@ <example> <title> Simple fetch of data based on Primary Key</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); print_r($person); -?> + ]]> </programlisting> </example> @@ -660,11 +671,11 @@ <example> <title> Simple fetch of data based on Key and Value</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get('email','test@example.com'); print_r($person); -?> + ]]> </programlisting> </example> @@ -722,10 +733,10 @@ <example> <title> Simple fetch of data based on Primary Key</title> <programlisting role="php"><![CDATA[ -<? + $person = DataObjects_Person::staticGet(12); print_r($person); -?> + ]]> </programlisting> </example> @@ -737,10 +748,10 @@ <example> <title> Simple fetch of data based on Primary Key</title> <programlisting role="php"><![CDATA[ -<? + $person = DB_DataObject::staticGet('DataObjects_Person',12); print_r($person); -?> + ]]> </programlisting> </example> @@ -769,12 +780,12 @@ <example> <title> Simple find of data based on Object Vars</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->hair = 'red'; $person->has_glasses = 1; $number_of_rows = $person->find(); -?> + ]]> </programlisting> </example> @@ -813,7 +824,7 @@ <example> <title> Simple find and fetch of data based on Object Vars</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->hair = 'red'; @@ -826,7 +837,7 @@ $people[] = $person; echo "GOT {$person->name}<BR>"; } -?> + ]]> </programlisting> </example> @@ -927,12 +938,12 @@ <example> <title> Simple fetch and update</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $person->name='fred'; $person->update(); -?> + ]]> </programlisting> </example> @@ -956,12 +967,12 @@ <example> <title> Simple fetch and updated</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->removed=1; $person->whereAdd('age > 21'); $person->update(); -?> + ]]> </programlisting> </example> @@ -1002,11 +1013,11 @@ <example> <title> Simple insert </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->name='fred'; $id = $person->insert(); -?> + ]]> </programlisting> </example> @@ -1047,7 +1058,7 @@ <title> Simple Delete </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $person->delete(); @@ -1058,7 +1069,7 @@ $person->delete(TRUE); -?> + ]]> </programlisting> </example> @@ -1144,14 +1155,14 @@ <example> <title> raw Queries on the database </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->query("select * from {$this->__table} where id > 12"); while ($person->fetch()) { echo $person->name; } -?> + ]]> </programlisting> </example> @@ -1177,7 +1188,7 @@ <example> <title> Adding select statements</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->selectAdd(); $person->selectAdd('id,name'); @@ -1193,7 +1204,7 @@ -?> + ]]> </programlisting> </example> @@ -1240,7 +1251,7 @@ <example> <title> Adding Where Statements</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->whereAdd('age > 12'); $person->whereAdd('age < 30'); @@ -1258,7 +1269,7 @@ echo "$person->id} {$person->name}<BR>"; } -?> + ]]> </programlisting> </example> @@ -1307,7 +1318,7 @@ <example> <title> Setting the Limit</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->limit(2); $person->find(); @@ -1326,7 +1337,7 @@ -?> + ]]> </programlisting> </example> @@ -1374,14 +1385,14 @@ <example> <title> setting the order by</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->orderBy('name'); $person->orderBy('age, eye'); $person->find(); -?> + ]]> </programlisting> </example> @@ -1422,14 +1433,14 @@ <example> <title> Setting the Group by </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->groupBy('name'); $person->groupBy('age, eye'); $person->find(); -?> + ]]> </programlisting> </example> @@ -1519,7 +1530,7 @@ will always attempt to find primary keys that match the value of field, the getLinks() methods will auto load the related object into $object->_tablename_anything </para> - + <para> The other way of using getLink() is to use it with the second parameter which is the table name of the related table, it will then query the primary key on that table to see if it matches the value of the requested row. @@ -1529,12 +1540,39 @@ </refsect1> - - - - - - + + <refsect1> + <title>Using link ini files for table links</title> + <para> + DB_DataObject Version 0.3 introduced the ability to create link ini files so you can map rows to other database + columns using an ini file this ini file should have the name databasename.links.ini, and be placed in the + same folder as the databasename.ini file that is created automatically by createTables.php + </para> + <para> + The Ini file contains a section for each table, then the row that is linked equal to the table and row + that it should locate the row from. + <example> + <title> An example databasename.links.ini file</title> + <programlisting role="ini"><![CDATA[ + +; for table person +[person] +; link value of eycolor to table colors, match name column +eyecolor = colors:name +; link value of owner to table grp, match id column +owner = grp:id +; link value of picture to table attachments, match id column +picture = attachments:id + + + ]]> + </programlisting> + </example> + </para> + </refsect1> + + + <refsect1> <title>::getLink()</title> <para> @@ -1552,14 +1590,14 @@ <example> <title> Getting the related object </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $group = $person->getLink('group_owner'); echo $group->name; $group = $person->getLink('colourid','hair'); -?> + ]]> </programlisting> </example> @@ -1664,13 +1702,13 @@ <example> <title> Loading all the related objects </title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(1079); $person->getLinks(); print_r($person); -?> + ]]> </programlisting> </example> @@ -1801,7 +1839,7 @@ <!-- ****************************************** -AutoForm Utilities and Debugging +AutoForm Utilities Validation and Autoloading ******************************************* @@ -1812,9 +1850,9 @@ <refentry id="packages.database.db-dataobject.utils"> <refnamediv> - <refname>AutoForm Utilities and Debugging</refname> + <refname>Auto Form Utilities, Validation, Autoloading </refname> <refpurpose> - ::setFrom(), ::debugLevel() + ::setFrom(), ::validate(), and DB_DataObject::staticAutoLoad() </refpurpose> </refnamediv> @@ -1836,7 +1874,7 @@ <example> <title> Copying data from post or object</title> <programlisting role="php"><![CDATA[ -<? + $person = new DataObjects_Person; $person->get(12); $person->setFrom($_POST['input']); @@ -1854,7 +1892,7 @@ $person->update(); -?> + ]]> </programlisting> </example> @@ -1866,10 +1904,147 @@ </para> + </refsect1> + + + + + <refsect1> + <title>::validate()</title> + <para> + Either validates data as Integers or strings, otherwise calls user defined validation methods + </para> + <funcsynopsis> + <funcprototype> + <funcdef>(mixed boolean or array)<function>::validate</function></funcdef> + <paramdef><parameter></parameter></paramdef> + </funcprototype> + </funcsynopsis> + <para> + check all the objects variables to see if they are valid, by default this means is a column an integer + or string, if you define methods like validateEmail(), in your extended class then it will be called to + validate that rows data. + </para> + <para> + Note: that this validation depends on the PEAR validation package + + <example> + <title>validate usage</title> + <programlisting role="php"><![CDATA[ + +$person = new DataObjects_Person; +$person->get(12); +$person->setFrom($_POST['input']); +$val = $person->validate(); +if ($val === TRUE) { + $person->update(); +} else { + foreach ($val as $k=>$v) { + if ($v) { + echo "there was something wrong with ($k)"; + } + } +} + + + + ]]> + </programlisting> + </example> + + + </para> + <para> + + To add a validation routine to your extended class you should create a method with the name, ValidateXXXXXXX + where XXXXX is the name of the row to validate. + <example> + <title>validate methods</title> + <programlisting role="php"><![CDATA[ +/* inside class DataObject_Person */ +function validateEmail() { + return Validate::email($this->email, true); +} + +function validateHomepage() { + return Validate::url($this->homepage, true); +} +function validateDate() { + return Validate::date($this->date, "%d-%m-%Y", array(01,01,1970), array(01,01,2030)); +} + + ]]> + </programlisting> + </example> + Refer to the Validation package for more details on Validation methods. + + </para> </refsect1> + + + + <refsect1> + <title>::staticAutoloadTable()</title> + <para> + automatically load (include a DataObject class) + </para> + <funcsynopsis> + <funcprototype> + <funcdef>string classname<function>::staticAutoLoadTable</function></funcdef> + <paramdef>string <parameter>tablename</parameter></paramdef> + </funcprototype> + </funcsynopsis> + <para> + based on the config file, automatically includes the class definition for a table + and returns the class name + <example> + <title> Auto loading a tables class </title> + <programlisting role="php"><![CDATA[ + +$personclass = DB_DataObject::staticAutoloadTable('person'); +if (!$personclass) { + echo "NO PERSON TABLE exists.."; + exit; +} + +$person = new $personclass +$person->get(12); + + + ]]> + </programlisting> + </example> + </para> + </refsect1> - + + + + + + + + + </refentry> + <!-- + +****************************************** + Debugging + +******************************************* + +--> + + <refentry id="packages.database.db-dataobject.debugging"> + <refnamediv> + <refname>Debugging</refname> + <refpurpose> + DB_DataObject::debugLevel() ::debug() + </refpurpose> + </refnamediv> + + <refsect1> <title>DB_DataObject::debugLevel()</title> @@ -1888,7 +2063,7 @@ <example> <title> Setting the debugging level </title> <programlisting role="php"><![CDATA[ -<? + // turn debugging high DB_DataObject::debugLevel(5); $person = new DataObjects_Person; @@ -1899,7 +2074,7 @@ DB_DataObject::debugLevel(); -?> + ]]> </programlisting> </example> @@ -1909,6 +2084,48 @@ </refsect1> + <refsect1> + <title>DB_DataObject::debug()</title> + <para> + using the built in debug output of DB_DataObject + </para> + <funcsynopsis> + <funcprototype> + <funcdef><function>DB_DataObject::debug</function></funcdef> + <paramdef>string <parameter><optional>message</optional></parameter></paramdef> + <paramdef>string<parameter><optional>subject</optional></parameter></paramdef> + <paramdef>int <parameter><optional>debug level</optional></parameter></paramdef> + </funcprototype> + </funcsynopsis> + <para> + Outputs data to the screen, to show you what is happening in the application. + </para> + <para> + Note that in production mode, the debugger is disabled. + <example> + <title> Setting the debugging level </title> + <programlisting role="php"><![CDATA[ + + +$person = new DataObjects_Person; +$person->get(12); + +// always prints +$person->debug('just got the person, about to set stuff', 'my application',0); +$person->setFrom($_POST['input']); + +// only prints if debuglevel is set +$person->debug('just set the variables, about to update', 'my application',1); +$person->update(); + + + ]]> + </programlisting> + </example> + + + </para> + </refsect1> </refentry>