Instructions:
parameters: --database : database name (required option) --location : specify where to create the files (default is current directory) --templates : specify the location of the templates (default is "templates") --namespace : override config file's default namespace
--tables-regex : add tables by perl regular expression
parameters with * can be used more then once.
For comments/suggestions please e-mail,msn,google talk, google wave me at kfirufk@gmail.com.
Since version 0.4, in order to prevent code duplication, common classes where seperated from the model class to MainModel.php and from the DbTable class to MainDbTable.php. these classes are already placed by the script in their appropriate places
class::toArray() - returns an array, keys are the column names
class::fetchAll() - fetch all rows
class::findOneBy
class::deleteRowByPrimaryKey() - in general it's used to delete the current loaded row class::delete($where) - delete rows in the table by $where class::countAllRows() - counts all rows class::getPrimaryKeyName() - returns the name of the primary key column class::countByQuery($where='') - count query results class::select2Paginator(Zend_Db_Select $select) - created a Zend_Paginator class by a given select class::fetchAll2Paginator() - fetch all rows into a Zend_Paginator class::fetchListToPaginator($where=null, $order=null, $count=null, $offset=null) - fetchs all rows optionally filtered by where, order, count and offset class::getTableName() - returns the table name class::getSelect($withFromPart=true,$resetColumns=true,$resetOrder=true,$resetLimitOffset=true) - returns a Zend_Db_Table_select object class::query2Paginator($query) - creates a Zend_Paginator for a query string
Example:
class for database table 'users':
===== example.php =======
<?php
/* The following code may be needed without the usage of Zend Framework MVC.
require_once("Users.php");
require_once("Zend/Db/Adapter/Mysqli.php"); require_once("Zend/Db/Table.php");
$db = new Zend_Db_Adapter_Mysqli(array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '
Zend_Db_Table::setDefaultAdapter($db);
$users = new Default_Model_Users();
// example 1: fetchs an array of Default_Model_Users filtered by username eq 'admin'.
$data=$users->fetchList('username = \'admin\'',null,1); var_dump($data[0]->toArray());
// fetchs one row where username eq 'admin' $users->findOneByUsername('admin'); var_dump($users->toArray());
// fetches all rows where username eq 'admin' $data=$users->findByUsername('admin'); var_dump($data[0]->toArray());
// finds a row where username eq 'admin' and saves it $users->findOneByUsername('admin'); $users->setUsername('root'); $users->save();
// finds a row by primary key 1 and delete it $users->setId(1); $users->deleteRowByPrimaryKey();
// updates username in row 9 $users->setId(9); $users->setUsername('newuser'); $users->save();
?>
==== end of example.php ==
** more examples can be found in testzdmg directory.
I want to thank the following people for their feedback/patches/comments: Charles Spraggs,Richard Hamilton,AJIT DIXIT,Aleksandar Scepanovic,Ivan Mosquera Paulo
Changelog is created by svn2cl (http://arthurdejong.org/svn2cl).