I'm currently working on a project where I use Zend Framework with Propel.
I'm looking for something that'll create Zend_Forms for Propel objects, preferably in a similar way to django's modelforms
Is there anything out there that does this already, and if not, what would be the best way to go about creating something like this?
One of my colleagues has provided the following as a "starting place"
<?php
class TestController extends Zend_Controller_Action
{
public function indexAction()
{
$product_table = ProductPeer::getTableMap();
$product_columns = $product_table->getColumns();
$elements = array();
foreach($product_columns as $col_name => $col_data)
{
$col_name = ucwords(str_replace('_', ' ', strtolower($col_name)));
switch($col_data->getType())
{
case 'TINYINT':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'SMALLINT':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'INTEGER':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'FLOAT':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'DOUBLE':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'VARCHAR':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'DECIMAL':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'LONGVARCHAR':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'DATE':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
case 'TIMESTAMP':
$element = new Zend_Form_Element_Text(
$col_name,
array(
'label' => $col_name
)
);
break;
default:
die("Unknown colum type: " . $col_data->getType());
}
$elements[] = $element;
echo $element;
}
die("END");
}
}