zend decorator表单在表中创建行表

时间:2012-06-26 14:31:01

标签: php zend-framework zend-form zend-form-element

我有以下代码,我想在行表中创建表单。第一个for循环是一个表,第二个for循环是子表。这些子表我将使用javascript来显示和隐藏它们使用加号/减号按钮。

    <?php

class Application_Form_LineData extends Zend_Form
{
    private $lineId;
    private $dataId;
    private $name;

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    }

    public $elementDecoration = array(
            'ViewHelper',
            array(array('data' => 'HtmlTag'), array('tag' => 'td'))
    );

    public $elementRowDecoration = array(
            'ViewHelper',
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    );

    public $elementTableDecoration = array(
            'ViewHelper',
            array(array('data' => 'HtmlTag'), array('tag' => 'td')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    );

    public function setLineId($lineId)
    {
        $this->lineId = $lineId;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function setDataId($dataId)
    {
        $this->dataId = $dataId;
    }

    public function startform($entries)
    {
        $this->setMethod('post') ->setAttrib('enctype', 'multipart/form-data');
        //$this->setName('linedata');
        //$this->setAction($_SERVER["REQUEST_URI"]);
        //$this->setAction('line/submit');
        $count = count($entries);

        for($i=0;$i<$count;$i++){

            $this->addElement('text', 'lineid_'.$entries[$i]['PGA_Id'], array(
                    'required' => true,
                    'value'     => $entries[$i]['PGA_Id'],

                    'decorators' => $this->elementDecoration,

            ));

            $this->addElement('text', 'name_'.$entries[$i]['PGA_Name'], array(
                    'required' => true,
                    'value'     => $entries[$i]['PGA_Name'],
                    'readonly' =>true,
                    'decorators' => $this->elementDecoration
            ));

            $this->addElement('checkbox', 'check'.$entries[$i]['PGA_Id'], array(
                    'decorators' => $this->elementDecoration,


            ));
            $this->setElementDecorators(
                    array(
                            'ViewHelper',
                            'Label'
                    ),
                    array(
                            'lineid_'.$entries[$i]['PGA_Id'],
                            'name_'.$entries[$i]['PGA_Name'],
                            'check'.$entries[$i]['PGA_Id']
                    )

            );


            // Data sets for each line
            /*
            $countData = count($entries[$i]['Data_Set']);
            for($x=0;$x<$countData;$x++){

            $this->addElement('hidden', 'dataid_'.$entries[$i]['Data_Set'][$x]['PGA_Id'], array(
                    'required' => true,
                    'decorators' => $this->elementDecoration,
                    'decorators' => $this->elementRowDecoration,
                    //'decorators' => $this->elementTableDecoration,
            ));

            $this->addElement('text', 'name_'.$entries[$i]['Data_Set'][$x]['PGA_Name'], array(
                    'required' => true,
                    'value'     => $entries[$i]['Data_Set'][$x]['PGA_Name'],
                    'readonly' =>true,
                    'decorators' => $this->elementDecoration
            ));

            $this->addElement('hidden', 'path_'.$entries[$i]['Data_Set'][$x]['PGA_Path'], array(
                    'required' => true,
                    'value'     => $entries[$i]['Data_Set'][$x]['PGA_Path'],
                    'readonly' =>true,
                    'decorators' => $this->elementDecoration
            ));

            $this->addElement('checkbox', 'check'.$entries[$i]['Data_Set'][$x]['PGA_Id'], array(
                    'decorators' => $this->elementDecoration
            ));
            }
            */

        }
        //show var here
        //var_dump($this->lineId);

        $this->addElement('submit', 'submit', array(
                'ignore'   => true,
                'label'    => 'Submit',
                'decorators' => $this->elementDecoration
        ));
        /*
         $this->setElementDecorators(array(
                'ViewHelper',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td')),
                //array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
         ));
        */
        $this->setDecorators(array(
                'FormElements',
                array(array('data'=>'HtmlTag'),array('tag'=>'table')),
                'Form'
        ));

        //print_r($this);
        //exit();

        return $this;
    }

    //$this->setDecorators(array('FormElements', array('SimpleTable', ), 'Form'));


}

0 个答案:

没有答案