odea/library/Libs/Row.php

33 lines
863 B
PHP
Raw Normal View History

2012-02-02 17:29:14 +00:00
<?php
abstract class Libs_Row extends Zend_Db_Table_Row_Abstract
{
public function __construct(array $input = array())
{
$class = explode('_', get_class($this));
$this->_tableClass = 'Table_' . array_pop($class) . 's'; // le 's' final
parent::__construct($input);
$cols = $this->_table->info(Zend_Db_Table_Abstract::COLS);
if (!isset($input['data'])) {
$input['data'] = array_combine($cols, array_pad(array(),count($cols),null));
}
$this->_data = $input['data'];
}
public function getForm($form = null)
{
$formObject = $this->getTable()->getForm($form);
if ($this->_data[$this->_primary[1]] != null && $form == null) {
$formObject->populate($this->_data);
}
return $formObject;
}
public function save()
{
$form = $this->getForm();
if (!$form->isValid($this->_data)) {
return false;
}
return parent::save();
}
}