Welcome to PHP Somms Business Framework
PHP Somms Business Framework is a framework data access layer for PHP. Its goal is to have an easy, simple and powerfull way to access data, having integration with AMFPHP in mind.
There is a template available for MyGeneration? Software, since it is an evolution of Justin Greenwood's simple PHP template (from My Generation Software). It has been improved, and expanded.
- We have corrected a lot of bugs
- We added Oracle support, taking and adapting the phpBB oracle class
- Now it follows the Builder Pattern
- Now you can have your custom code, that will not be overwritten.
- We added AMFPHP integration, making Builders act as services.
Components
MyGeneration? Template
Inside MyGenerationTemplate? folder you will find the template for MyGeneration?. This script will generate all the code once you have selected a database.
It is important to point to the "business/generated" folder for the output.
How To
Prerequisites
You need a database at least in 1st normal form. In other words, you need one table per entity. This is very important, because each table will have an associated class in code.
Installation and Generation
First of all, copy the project file structure to your project root folder, except MyGenerationTemplate? folder. After that, run MyGeneration?, configure your database connection, and open the PHP_BusinessObject.jgen script. Execute it, select the tables, and point to your "business/generated" as output folder. And there it is!
Generated Files
Under business folder you have to folders: custom and generated. Both contains files for the generated class, but the files under custom folder will not be overwritten if you run the code generation again.
Every table selected in the generation step will have a file in both folders with the "Builders" classes. In addition, a file with entity classes is in "generated" folder.
Generated Classes
The classes are defined in the "php_classes_[dbname].php" file, where [dbname] is the database name.
You will have two classes per table, one for the entity and other one for the collections: class [entity] and class [entity]Collection, where [entity] is exactly the name of the table. Our advice is to name the tables as the entity in singular.
Generated Builders
The builders are defined on each "[entity]Builder_gen.php". They offer the basic tools to access entities. If you have a relational database, it will include methods to get the related entities.
Custom Builders
The custom builders are the real ones, those you are going to use in your code. If you want to add your custom code to the builder, use this file. Once it is generated the first time, it will not we overwritten the next time you update your database and generate the new code.
Configuration
Go to config.php and set your options.
Have a good development!
Little example
Suppose you have generated class for "noticia" entity, and customized config.php
<?php
// include necesary builders for classes
require_once(dirname(__FILE__). "/config.php");
require_once(dirname(__FILE__). "/business/custom/noticiaBuilder.php");
$builder = new noticiaBuilder();
// Get all objects
$noticias = $builder->GetItems();
// Create a new one
$nuevosParametros = array('Titular' => 'Hola', 'Cuerpo' => 'Lorem Ipsum Dolor Amet'); // Tip: You can use directly the parameters received from POST o GET if you name the fields correctly.
$nueva_noticia = $builder->createItem($nuevosParametros);
//Finally, close all
$builder->closeAll();
?>
