PHP Classes

MVC Tool: Generate model classes to access database tables

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 308 All time: 7,327 This week: 107Up
Version License PHP version Categories
mvc-tool-model-gen 2GNU General Publi...3.0PHP 5, Databases, Code Generation
Description 

Author

This class can generate model classes to access database tables.

It uses a database connection established by an instance of the PDO class and retrieves the definitions of a given database table or view.

The class can generate code for a model class with getter and setter functions for each database table field and a to string function that returns the values of the fields as an associative array.

It can support several types of databases supported by PDO but currently only MySQL support is implemented.

Picture of Ettore Moretti
  Performance   Level  
Name: Ettore Moretti is available for providing paid consulting. Contact Ettore Moretti .
Classes: 12 packages by
Country: Italy Italy
Age: ???
All time rank: 107741 in Italy Italy
Week rank: 91 Up2 in Italy Italy Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
require_once 'modelGenerator.class.php';

$db = new PDO("mysql:host=localhost;dbname=timebarter", 'root', '', null);
$table='old_log_table';
$outPath='ModelFolder/';

$myModelGenerator= new ModelGenerator($db, $outPath);
$myModelGenerator->createModelFromTableOrView($table);


Details

MVC Tool - Automatic Model Generator [EN] Several times I have to use MVC framework for the creation of a portal or a webapp. And many times, the dba had already built the architecture of the db. One of the most annoying things that I happen to do, is to 'translate' all tables or views, in Model classes. So one day, I created this simple but useful class. It reads from db information and metadata of the table (or view) and returns them in the form of a class Model Of course not always the class is ready for use, according to your needs you should make changes or add some function, but I am of the opinion that it is better to make changes that write from 0 all model, especially when the tables exceed 100 units. In short, a Developer Tool convenient and fast, at least to me has saved many hours of work ... I hope will be helpful to you. P.S. The tool as it is, only works with mysql db. I did it so that you can implement the functions of data recovery from any type of db. Just a little bit! once implemented a recovery from the new db, if you want to write the solution in the forum dedicated to the class, so that it is available to all ... [IT] Diverse volte mi è capitato di utilizzare framework MVC per la realizzazione di un portale o una webapp. E molte volte, il dba aveva già realizzato l'architettura del db. Una delle cose che più fastidiose che mi capita di fare, è quella di "tradurre" tutte le tabelle o viste, in classi Model. Così, un giorno ho creato questa semplice ma utile classe. Che legge dal db le informarmazioni e metadati della tabella (o vista) e li riporta sotto forma di una classe Model... Ovviamente non sempre la classe è pronta per l'utilizzo, a seconda delle necessità sarà opportuno fare delle modifiche o aggiungere qualche function, ma sono del parere che è meglio apportare delle modifiche che scrivere da 0 tutti i model, sopratutto quando le tabelle superano le 100 unità. Insomma un Developer Tool comodo e veloce, almeno a me ha risparmiato parecchie ore di lavoro...spero possa essere d'aiuto anche a voi. P.S. Il tool così com'è, funziona solo con db mysql. Ho fatto in modo che possiate implementare le funzioni di recupero dei dati da ogni tipo di db. Basta solo un po di ingegno!, una volta che avrete implementato un recupero dal nuovo db, se volete potrete comunicarmelo in modo da renderlo disponibile a tutti...

  Files folder image Files  
File Role Description
Files folder imageModelFolder (1 file)
Accessible without login Plain text file index.php Example Example script
Plain text file modelGenerator.class.php Class Class source
Accessible without login Plain text file README Data Documentation

  Files folder image Files  /  ModelFolder  
File Role Description
  Accessible without login Plain text file read.txt Data Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:308
This week:0
All time:7,327
This week:107Up