Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created December 10, 2009 14:46
Show Gist options
  • Save inxilpro/253364 to your computer and use it in GitHub Desktop.
Save inxilpro/253364 to your computer and use it in GitHub Desktop.
Sample code output from Galahad_Tool (see http://github.com/inxilpro/Galahad-FE/ for the rest of the code)
<?php
class Default_Form_User extends Zend_Form
{
public function init()
{
// Use the init() method to generate your form
$this->addElement('text', 'id', array(
'label' => 'Id',
'required' => false,
));
$this->addElement('text', 'username', array(
'label' => 'Username',
'required' => false,
));
}
}
<?php
class Default_Model_Collection_User extends Galahad_Model_Collection
{
}
<?php
class Default_Model_DataMapper_User extends Galahad_Model_DataMapper
{
public function fetchAll()
{
$dao = $this->getDao();
$data = $dao->fetchAll();
return new Default_Model_Collection_User($data->toArray());
}
public function fetchByPrimary($primaryKey)
{
$dao = $this->getDao();
$data = $dao->fetchByPrimary($primaryKey);
if (!$data) {
return false;
}
return new Default_Model_User($data);
}
public function save(Galahad_Model_Entity $entity)
{
$data = $entity->getData();
$dao = $this->getDao();
return $dao->save($data);
}
public function delete(Galahad_Model_Entity $entity)
{
$primaryKey = $entity->getId(); // TODO: Assumes propery 'id' is primary key
return $this->deleteByPrimary($primaryKey);
}
public function deleteByPrimary($primaryKey)
{
$dao = $this->getDao();
return $dao->deleteByPrimary($primaryKey);
}
}
<?php
class Default_Model_DbTable_User extends Galahad_Model_DbTable
{
protected $_name = 'user';
}
<?php
class Default_Model_User extends Galahad_Model_Entity
{
/**
* Gets the 'id' property
*
* @return mixed
*
*/
public function getId()
{
return $this->_getPropertyData('id');
}
/**
* Sets the 'id' property
*
* @param mixed $id
* @return Galahad_Entity
*
*/
public function setId($id)
{
return $this->_setPropertyData('id', $id);
}
/**
* Gets the 'username' property
*
* @return mixed
*/
public function getUsername()
{
return $this->_getPropertyData('username');
}
/**
* Sets the 'username' property
*
* @param mixed $username
* @return Galahad_Entity
*/
public function setUsername($username)
{
return $this->_setPropertyData('username', $username);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment