cvs: peardoc /en/package/database mdb-querytool.xml /en/package/database/mdb-querytool object.xml

From: Date: Sun, 25 Feb 2007 20:06:26 +0000
Subject: cvs: peardoc /en/package/database mdb-querytool.xml /en/package/database/mdb-querytool object.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-9473@lists.php.net to get a copy of this message
hugoki Sun Feb 25 20:06:26 2007 UTC Added files: /peardoc/en/package/database/mdb-querytool object.xml Modified files: /peardoc/en/package/database mdb-querytool.xml Log: - initial doc of return class feature http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/mdb-querytool.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/database/mdb-querytool.xml diff -u peardoc/en/package/database/mdb-querytool.xml:1.2 peardoc/en/package/database/mdb-querytool.xml:1.3 --- peardoc/en/package/database/mdb-querytool.xml:1.2 Sun Feb 27 19:16:07 2005 +++ peardoc/en/package/database/mdb-querytool.xml Sun Feb 25 20:06:26 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <sect1 id="package.database.mdb-querytool"> <title>MDB_QueryTool</title> @@ -11,6 +11,7 @@ </para> &package.database.mdb-querytool.intro; + &package.database.mdb-querytool.object; &package.database.mdb-querytool.api; </sect1> http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/mdb-querytool/object.xml?view=markup&rev=1.1 Index: peardoc/en/package/database/mdb-querytool/object.xml +++ peardoc/en/package/database/mdb-querytool/object.xml <refentry id="package.database.mdb-querytool.object"> <refnamediv> <refname>Object</refname> <refpurpose> An introduction to the usage of Objects with MDB_QueryTool </refpurpose> </refnamediv> <refsect1 id="package.database.mdb-querytool.object.description"> <title>MDB_QueryTool Object Description</title> <para> It is possible to use Objects as result. A comprehensive example may be seen in the <link linkend="package.database.mdb-querytool.intro"> intro</link>. </para> <para> But using objects is not a simple alternative to using arrays as result. It is also possible to register an own Class to be resulted instead of the default MDB_QueryTool_Result_Row. The new resulting class has to be child of the MDB_QueryTool_Result_Row class. </para> </refsect1> <refsect1 id="package.database.mdb-querytool.object.example1"> <title>Example 1 - Change the default result class</title> <para> To change the resulting class the method <methodname>setReturnClass</methodname> is used. <programlisting role="php"> <![CDATA[ require_once 'MDB/QueryTool.php'; require_once 'MDB/QueryTool/Result/Object.php'; define('TABLE_CARS', 'cars'); $dsn = 'mysql://user:pass@host/dbname'; /** * Let's suppose the "cars" table has the following fields: * (id, model, hp, color, clima, price) */ class Car extends MDB_QueryTool { public $table = TABLE_CARS; } class CarEntity extends MDB_QueryTool_Result_Row { } //instanciate an object of the Car class $car = new Car($dsn); $car->useResult('object'); $car->setReturnClass('CarEntity'); ]]> </programlisting> </para> </refsect1> <refsect1 id="package.database.mdb-querytool.object.controllingclassvariableaccess"> <title>Controlling class variable access</title> <para> This can now be used to implement getter and setter and thus regulate the accessability to the values. In order to block the access to the class variables from outside they have to be declared as protected. Declaring them as private would result in also blocking the parent class, which gets the data, of accessing them. Of course when doing so corresponding methods have to be implemented to access the variables again. </para> </refsect1> <refsect1 id="package.database.mdb-querytool.object.example2"> <title>Example 2 - Restricting class variable access</title> <para> To keep the example short only methods for dealing with model, hp and clima have been implemented. <programlisting role="php"> <![CDATA[ require_once 'MDB/QueryTool.php'; require_once 'MDB/QueryTool/Result/Object.php'; define('TABLE_CARS', 'cars'); $dsn = 'mysql://user:pass@host/dbname'; /** * Let's suppose the "cars" table has the following fields: * (id, model, hp, color, clima, price) */ class Car extends MDB_QueryTool { public $table = TABLE_CARS; } class CarEntity extends MDB_QueryTool_Result_Row { protected $id; protected $model; protected $hp; protected $color; protected $clima; protected $price; public function getModel() { return $this->model; } public function setModel($model) { $this->model = $model; } public function getHp() { return $this->hp; } public function setHp($hp) { $this->hp = $hp; } public function getClima() { if ($this->clima) { return true; } else { return false; } } public function setClima($clima) { if ($clima) { $this->clima = 1; } else { $this->clima = 0; } } } //instantiate an object of the Car class $car = new Car($dsn); $car->useResult('object'); $car->setReturnClass('CarEntity'); ]]> </programlisting> </para> </refsect1> <refsect1 id="package.database.mdb-querytool.object.outlook"> <title>Outlook</title> <para> This example only demonstrates a very basic feature. But it enables for example the implementation of Decorators. Every feature of modern OOP is now possible to implement. </para> </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 (#9473) next »