用于推进对象的Zend_Form创建

时间:2010-03-09 22:44:04

标签: zend-framework zend-form propel

我目前正在开发一个项目,我在其中使用Zend Framework和Propel。

我正在寻找能够为Propel对象创建Zend_Forms的东西,最好是以与django的模型相似的方式

那里有什么东西可以做到这一点,如果没有,那么创造这样的东西最好的方法是什么?

1 个答案:

答案 0 :(得分:1)

我的一位同事提供了以下“起点”

<?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");
    }
}