listTables(); foreach($tables as $table) { // need to remove underline first, ucwords, and then remove space $name = str_replace(' ', '', ucwords(str_replace('_', ' ', $table))); // create new class generator $class = new Zend_CodeGenerator_Php_Class(); // configure docblock $docblock = new Zend_CodeGenerator_Php_Docblock(array( 'shortDescription' => $name . ' model', 'tags' => array( array( 'name' => 'author', 'description' => 'Joey Rivera', ) ) )); // set name and docblock $class->setName('Ct_Model_' . $name); $class->setDocblock($docblock); // get all fields $fields = $db->describeTable($table); // want to track primary ids for table $primary = array(); // add to columns each field with a default value $columns = array(); foreach($fields as $field) { // if int field default to 0 $columns[$field['COLUMN_NAME']] = strpos($field['DATA_TYPE'], 'int') !== false ? 0 : ''; // track primary field(s) for table if($field['PRIMARY']) { $primary[] = $field['COLUMN_NAME']; } } // add data array property to class $class->setProperty(array( 'name' => '_data', 'visibility' => 'protected', 'defaultValue' => $columns, 'docblock' => array( 'tags' => array( new Zend_CodeGenerator_Php_Docblock_Tag(array( 'name' => 'var', 'description' => 'array Maps to all fields in table' ) ) ) ) )); echo $class->generate() . PHP_EOL; file_put_contents($temp_path . $name . '.php', 'generate()); // create zend_db_table_abstract $db_class = new Zend_CodeGenerator_Php_Class(); $db_class->setName('Ct_Model_DbTable_' . $name); $db_class->setDocblock(new Zend_CodeGenerator_Php_Docblock(array( 'shortDescription' => $name . ' db table abstract', 'tags' => array( array( 'name' => 'author', 'description' => 'Joey Rivera', ) ) ))); $db_class->setExtendedClass('Zend_Db_Table_Abstract'); $db_class->setProperty(array( 'name' => '_name', 'visibility' => 'protected', 'defaultValue' => $table, 'docblock' => array( 'tags' => array( new Zend_CodeGenerator_Php_Docblock_Tag(array( 'name' => 'var', 'description' => 'string Name of db table' )) ) ) )); if(count($primary)) { $db_class->setProperty(array( 'name' => '_primary', 'visibility' => 'protected', 'defaultValue' => count($primary) > 1 ? $primary : $primary[0], 'docblock' => array( 'tags' => array( new Zend_CodeGenerator_Php_Docblock_Tag(array( 'name' => 'var', 'description' => 'string or array of fields in table' )) ) ) )); } echo $db_class->generate() . PHP_EOL; file_put_contents($temp_path . 'DbTable/' . $name . '.php', 'generate()); }