[Solar-talk] a base class for generic domain models
Rodrigo Moraes
rodrigo.moraes at gmail.com
Thu Jan 18 00:31:08 PST 2007
Hi everybody,
I've been working on a base class for models that acts like a
Solar_Sql_Row or Rowset depending on the circunstances. It uses
internally methods from Solar_Sql_Table, so many things are automated.
There are some interesting results so far, like this example to
populate a form with row data:
$nodes = Solar::factory('Tipos_Model_Nodes');
$node = $nodes->fetch(1);
// create a form object populated with the node data
$form = $node->form(); <--- You call the form directly from the row! :-D
....or the rowset equivalent:
$nodes = Solar::factory('Tipos_Model_Nodes');
$list = $nodes->fetchAll();
foreach($list as $node) {
// create a form object populated with the node data
$form = $node->form();
}
Inside the method form(), you can restrict the columns you want to use
and set the form field properties, much like in
Solar_Content_Abstract, but in a more generic way (works for any
table) and called directly from the result.
You can also set custom methods in the models that uses the row/rowset
data directly:
public function getArea()
{
$areas = Solar::factory('Tipos_Model_Areas');
return $areas->fetch($this->area_id);
}
$node = $nodes->fetch(1);
$area = $node->getArea();
This is the basic idea: a base class for generic domain models. I
would like to know if you have worked on something related and to hear
your thoughts.
cheers,
rodrigo
More information about the solar-talk
mailing list