Location: PHPKode > projects > Porque - PHP object automation > porque-0.1.3/doc/ch01.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 1. What Porque is</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="Porque"><link rel="up" href="index.html" title="Porque"><link rel="previous" href="index.html" title="Porque"><link rel="next" href="ch02.html" title="Chapter 2. Planned features and bugfixes"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 1. What Porque is</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id340654"></a>Chapter 1. What Porque is</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="ch01.html#id334133">A quick example</a></dt><dd><dl><dt><a href="ch01.html#id333379">Input</a></dt><dt><a href="ch01.html#id331262">Output</a></dt><dt><a href="ch01.html#id351400">How to use the output</a></dt></dl></dd></dl></div><p>Porque is an automation engine for rapid development of typical PHP web applications. From an xml-defined data schema, it creates a database schema for use with MySQL 3.23.x and a set of PHP classes for use with PHP 4.2.1 and above.</p><p>Porque is different from other engines of the kind, like phpGem: it does not create a ready-made web application which is hard to customize, but an API. This API includes</p><div class="itemizedlist"><ul type="disc"><li><p>Getters and setters for the attributes of your classes.</p></li><li><p>Database persistence functions (load(), save()), which transparently load an object from the database and save it back (or create a new one, if it is not there).</p></li><li><p>HTML Templating which allows you to present the data of your objects in any way you want.</p></li></ul></div><p>
    </p><p>Porque features a lot of different types for your data (pk-auto, int, string, date, time, datetime, flag, 1:n references, n:m references) and handles these types consistently both with the database persistence functions and with the HTML templates. Once you have your schema defined, everything is ready and in place to add the semantics of your application.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id334133"></a>A quick example</h2></div></div><div></div></div><p>
        <a class="indexterm" name="id333857"></a>
			   To give you a quick idea of what porque does, here is a quick example of input and output of porque, how to use it, and what you can do with it.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id333379"></a>Input</h3></div></div><div></div></div><div class="example"><a name="id329174"></a><p class="title"><b>Example 1.1. The XML input file</b></p><pre class="programlisting">&lt;db name=&quot;porque&quot;&gt;
	   &lt;table name=&quot;product&quot;&gt;
	    &lt;column name=&quot;id&quot; type=&quot;pk-auto&quot;/&gt;
	    &lt;column name=&quot;title&quot; type=&quot;string&quot; precision=&quot;60&quot;/&gt;
	    &lt;column name=&quot;description&quot; type=&quot;string&quot; precision=&quot;6000&quot;/&gt;
	    &lt;column name=&quot;type&quot; type=&quot;ref&quot; ref=&quot;product_group&quot; visibility=&quot;both&quot; rightname=&quot;products&quot;/&gt;
	   &lt;/table&gt;

	   &lt;table name=&quot;product_group&quot;&gt;
	    &lt;column name=&quot;id&quot; type=&quot;pk-auto&quot;/&gt;
	    &lt;column name=&quot;name&quot; type=&quot;string&quot; precision=&quot;100&quot;/&gt;
	    &lt;column name=&quot;managers&quot; type=&quot;refmn&quot; ref=&quot;person&quot; visibility=&quot;both&quot; rightname=&quot;product_groups&quot;/&gt;
	   &lt;/table&gt;

	   &lt;table name=&quot;person&quot;&gt;
	    &lt;column name=&quot;id&quot; type=&quot;pk-auto&quot;/&gt;
	    &lt;column name=&quot;name&quot; type=&quot;string&quot; precision=&quot;20&quot;/&gt;
	    &lt;column name=&quot;birthday&quot; type=&quot;date&quot;/&gt;
	    &lt;column name=&quot;contract&quot; type=&quot;flag&quot;/&gt;
	   &lt;/table&gt;
   &lt;/db&gt;
   </pre></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id331262"></a>Output</h3></div></div><div></div></div><p>This will create the following files:

			   </p><div class="variablelist"><dl><dt><span class="term">tables.sql</span></dt><dd><p>
							   This file contains the SQL schema definition. You can pipe these SQL statements 
							   to MySQL and your schema will be created. There will be a table for each of the
							   <tt class="literal">&lt;table&gt;</tt> elements in the input file, as well as a table that tracks the 
							   m:n relation between product groups and managers.
						   </p></dd><dt><span class="term">base_product.class.inc, base_product_group.class.inc, base_person.class.inc</span></dt><dd><p>These classes implement the object management logic, the database persistence functions, and the functions used for HTML Form templating.</p></dd><dt><span class="term">product.class.inc, product_group.class.inc, person.class.inc</span></dt><dd><p>These classes extend the classes metioned above and are otherwise empty - they are for you to change, as they will not be overwritten when you change the XML definition file and recreate everything.</p></dd><dt><span class="term">product_form_template.tpl, product_group_form_template.tpl, person_form_template.tpl</span></dt><dd><p>Form templates for each class. These are automatically generated examples and can be used as a starting point.</p></dd></dl></div><p>
        </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id351400"></a>How to use the output</h3></div></div><div></div></div><p>The following example shows how to create a very simple page for editing entry data,
	   as well as creating new entries.</p><div class="example"><a name="id351420"></a><p class="title"><b>Example 1.2. Creating a bare-bone screen for editing persons</b></p><pre class="programlisting">
       &lt;?
       include_once('output/person.class.inc');

   (1) $persons = person::load_all();
       if (count($persons)) foreach($persons as $person) {
	   echo &quot;&lt;a href=\&quot;./personform.php?id=&quot;.$person-&gt;get_id().&quot;\&quot;&gt;&quot;;
	   echo htmlentities($person-&gt;get_name()).&quot;&lt;/a&gt;&lt;br&gt;&quot;;
       }
       echo &quot;&lt;a href=\&quot;./personform.php\&quot;&gt;New entry&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&quot;;

   (2) $u = new person($_GET['id']);

       echo &quot;Editing &quot; . ($_GET['id'] ? htmlentities($u-&gt;get_name()) : 'New entry').'&lt;br&gt;&lt;hr&gt;';

       if (array_key_exists('submit', $_POST)) {	
   (3)	$errors = $u-&gt;takein_values($_POST);
	   if ( !(is_array($errors) &amp;&amp; count($errors))) {		
   (4) 		$u-&gt;save();
	   }
       }

       $u-&gt;show_html_form($errors, './personform.php');
       ?&gt;      
	   </pre><p>This will give you the following html page:</p><div><img src="images/personform-empty.gif"></div><p>(1) Each generated class has a static function <tt class="methodname">load_all($clause='')</tt>, which loads an array list of objects of that class and returns it. The optional <tt class="literal">$clause</tt> parameter can contain SQL that is added after the <tt class="computeroutput">SELECT [columnlist] FROM [tablelist]</tt> part of the query.</p><p>The ensuing lines loop through the list and print a line for each person already in the 
	     table, creating a link that is passing the person's id as the <tt class="literal">GET</tt> parameter 
	     <tt class="literal">id</tt>.
	     </p><p>
	     (2) If an id is passed to the constructor of a porque-generated class, the object will be
	     loaded from the database before the constructor returns. Otherwise, an empty object is created.
	     </p><p>
	     (3) The <tt class="methodname">takein_values()</tt> function scans the data in the 
	     <tt class="literal">POST</tt> parameters and propagates the data to the object.
	     </p><p>
	     (4) The <tt class="methodname">save()</tt> function will save an existing object or create a new
	     object, depending on whether the classes primary key property is set or no. 
	     </p></div></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Porque </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. Planned features and bugfixes</td></tr></table></div></body></html>
Return current item: Porque - PHP object automation