-
Notifications
You must be signed in to change notification settings - Fork 2
Manual
$SETTINGS['types']['create_dto'] = true; $SETTINGS['types']['create_dao'] = true; $SETTINGS['types']['create_entity'] = true; $SETTINGS['types']['create_service'] = true; $SETTINGS['types']['create_interface'] = true; $SETTINGS['types']['create_errorconstants'] = true; $SETTINGS['types']['create_exception'] = true; $SETTINGS['types']['create_genericfiles'] = true;
Where;
$SETTINGS['types']['create_dto'] = true;
The core of this model structure, the class with all getters and setters. This is the type of object you get in return when querying the serivice later.
$SETTINGS['types']['create_dao'] = true;
This is where the combination of our entity and dto is used, to get/set/update the data in the database
$SETTINGS['types']['create_entity'] = true;
Used to describe the table we are working with, and also contain possible additions like relations and such.
$SETTINGS['types']['create_service'] = true;
A static shell to our dao, which also throws possible exceptions if needed.
$SETTINGS['types']['create_interface'] = true;
The interface that descibes our current service.
$SETTINGS['types']['create_errorconstants'] = true;
Catches all errors thrown throughout all our services, adds a unique ID to each and every one.
$SETTINGS['types']['create_exception'] = true;
The Exeption service, extends Zends own exception handling, with the possibility of extra settings here.
$SETTINGS['types']['create_genericfiles'] = true;
All the generic files, which all other types extend, so that it is easy customizable to add things to all daos/dtos at once.
This should be pretty self explained, the mysql database settings which you are intrested in mirroring with your models.
$SETTINGS['mysql_host'] = "localhost"; $SETTINGS['mysql_user'] = "mysql_user"; $SETTINGS['mysql_password'] = "mysql_password"; $SETTINGS['mysql_db'] = "mysql_db";
$ZendModelCreator->setDirectoryStructure( array( "ContainerDir" => "models", "DS" => "/", "DirectoryStructure" => array( 'DTO' => 'api', 'DAO' => 'dao', 'ENT' => 'persistence', 'SRV' => 'service', 'INT' => 'api', 'EXC' => 'service', 'GEN' => 'db' ), "FileNames" => array( 'DTO' => '[tbl]DTO.php', 'DAO' => '[tbl]DAO.php', 'ENT' => '[tbl]Entity.php', 'SRV' => '[tbl]Service.php', 'INT' => 'I[tbl]Service.php', 'EXC' => '[tbl]ServiceException.php' ) ) );
This is where you might want to customize to fit your needs, anything goes. The variable [tbl] used will be changed to what ever table the application is processing at the moment. DS is what kind if Directory seperator the system you are on is using. ContainerDir is the folder name, which everything ends up in, if you are using the function writePHPCreatedModelData()
The comments here are pretty self explained. Remember to make the folder writable by the server, if you are using the function writePHPCreatedModelData(); ` /**
- Either runt getPHPCreatedModelData to get the
- data for each file outputted in an HTML
<textarea>
element. */ //$ZendModelCreator->getPHPCreatedModelData();
/**
- Or run writePHPCreatedModelData to write all php-files
- to the specified directorys set with setDirectoryStructure. */ $ZendModelCreator->writePHPCreatedModelData(); `
After you have made your configuration, it is just a matter of putting the script on a webserver and surfing to whatever folder you have put the index.php in. For example: http://127.0.0.1/ZendModelCreator/ The code is then generated, and either stored in files or shown on the webpage generated.
We assume you already got a Zend Framework project set up, if you have not, we really recommend that you take a look at Mitchell Hashimoto's guide to set one up. We will be using his structure from now on, with some modifications. If you do not feel like coding this yourself, you could download Project 1, Hello World! to get started.
We will also assume that you used the function writePHPCreatedModelData(), so that you don't have to create and copy all files manually.
If you have set everything up correctly, this is as easy as;
- Include the service you want to use;
- require_once '{mysql_tablename}/service/{Mysql_tablename}Service.php';
- Retrieve all rows from your specified table name with this
- $rows = {Mysql_tablename}Service::retrieve{Mysql_tablename}s();
- Set it to the view as follows;
- $this->view->data = $rows;
Replace {mysql_tablename} with the table you want to access, replace {Mysql_tablename} with the table you want to access, but with Uppercase letter first.