输出Zend Form To Key =>值

时间:2011-04-21 08:52:18

标签: zend-framework zend-form

我想将Zend_Form对象输出为

array('name'=>'db'中的输入用户名,'description'=>'数据库中的描述');

到目前为止,如果我做

print_r((array)$ form);

我明白了:

{"\u0000*\u0000_attribs":{"name":"add","enctype":"multipart\/form-data","method":"post"},"\u0000*\u0000_decorators":{"FormElements":{"decorator":"FormElements","options":null},"HtmlTag":{"decorator":"HtmlTag","options":{"tag":"dl","class":"zend_form"}},"Form":{"decorator":"Form","options":null}},"\u0000*\u0000_defaultDisplayGroupClass":"Zend_Form_DisplayGroup","\u0000*\u0000_description":null,"\u0000*\u0000_disableLoadDefaultDecorators":false,"\u0000*\u0000_displayGroupPrefixPaths":[],"\u0000*\u0000_displayGroups":[],"\u0000*\u0000_elementDecorators":null,"\u0000*\u0000_elementPrefixPaths":[],"\u0000*\u0000_elements":{"name":{"helper":"formText"},"name_url":{"helper":"formText"},"description":{"helper":"formTextarea","rows":"10"}

etcetc,很多Zend存储

如果我这样做:

    $form = new Form_Administration_Movie_Add();
    $elements = $form->getElements();

    foreach($elements as $key => $element) {
     echo $key;
    }

我得到了一个字段列表,但是我不能做$ element-> getValue()因为我只得到0或1而没有实际数据。

想法?

1 个答案:

答案 0 :(得分:3)

$array = $form->getValues();

这有用吗? :)

修改:在调用$form->isValid($_POST)方法之前,您可能需要使用$form->populate($_POST)getValues()