A design for automatic generation of forms Zend.
Branch: master
Clone or download
ionixjunior Merge pull request #2 from jonathands/master
Changed the Readme and quotified the SQL statements
Latest commit cda882c Aug 21, 2012
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Forms
library renomeado arquivo do sql de mysql, editando readme, e passando sqls p… Jul 30, 2012
.project Add lib Zend, Symfony and Ionix. Add the database test, zend-form-gen… Apr 30, 2012
README renomeado arquivo do sql de mysql, editando readme, e passando sqls p… Jul 30, 2012
autoloader.php Add lib Zend, Symfony and Ionix. Add the database test, zend-form-gen… Apr 30, 2012
database-mysql.sql renomeado arquivo do sql de mysql, editando readme, e passando sqls p… Jul 30, 2012
database-postgres.sql Add lib Zend, Symfony and Ionix. Add the database test, zend-form-gen… Apr 30, 2012
zend-form-generator.php

README

This library is meant to create Zend Forms based on information retrieved from the database automatically.

Requirements for the usage:
PHP 5 >= 5.3.0

The form files are created based on tables existing at the database, so for each existing table a form file will be created.

To created the form files correctly each column of the table must contain a comment labeling the field, this comment will be used as the name of the generated field element of the form file being generated.

At the moment of the creation of each field in the form file, some validations are considered. If the field type is String, the attribute maxlength is used as a rule on Zend Form Element. If the field type is integer, the Zend_Validate_Int is used in the Zend Form Element. If the field deny null values on column, the validator Zend_Validate_NotEmpty and option required used. 

Also if the column is a foreign key, the form element will be a Zend_Form_Element_Select.

You can create the forms files in the following ways:
- Using the structure suggested by Zend ( verify Zend manual, section: recommended structure )
- Using your personal library ( using namespaces ) 


1) The database:

To generate the forms, you can use MySQL or PostgreSQL database systems. To use the library you must configure your database connection data in the zend-form-generator.php file.
The package comes with 2 test databases and the files used to handle each database system are "database-mysql.sql" and "database-postgresql.sql".

Remember, you need to insert a comment in all the columns of the database so the form generator can function properly.


2) Run the library:

To generate your forms execute the following commands using the PHP CLI:

Generating forms inside the Forms folder using structure recommended by Zend:
$ php zend-form-generator.php generate-forms Forms


Generating forms inside the Forms folder using a namespaces:
$ php zend-form-generator.php generate-forms Forms Name\Your\Namespace


Generating forms inside the Forms folder including the primary keys of tables.
$ php zend-form-generator.php generate-forms --primary-keys Forms
or
$ php zend-form-generator.php generate-forms --primary-keys Forms Name\Your\Namespace


In the near future decorators will be added to give the ability to customize the generated forms.

Enjoy!