简体   繁体   English

表单元素名称中的zend方括号

[英]zend square brackets in form element name

I have one problem with Zend Framework. 我对Zend Framework有一个问题。 I included into my form MultiCheckbox element and it adds square brackets to it's name in HTML(for example I need element with name tags, but ZF makes it tags[]). 我将其包含在表单MultiCheckbox元素中,并在HTML的名称中添加了方括号(例如,我需要带有名称标签的元素,但ZF使其成为标签[])。

When I use this form in my home development server everything just works fine. 当我在家庭开发服务器中使用此表单时,一切正常。 But then I uploaded code to production server it just went wrong. 但是后来我将代码上传到生产服务器时,它就出错了。 When putting to database I have to make column named tags[] and because php uses square brackets for arrays everything crashes and I can't use it in my view. 当放入数据库时​​,我必须创建名为tags []的列,并且因为php对数组使用方括号,所以所有崩溃都会发生,并且我无法在视图中使用它。

How could I solve this problem? 我该如何解决这个问题?

Square braquets is the normal way to define an array for data used with $_GET and $_POST methods. 方括号是为$_GET$_POST方法使用的数据定义数组的常规方法。

In your PHP script, you need to unserialize the array and parse or do what you want with your array. 在您的PHP脚本中,您需要反序列化数组并解析或对数组执行所需的操作。

<?php 
    //Example for $_REQUEST["item"] = "item[]=1&item[]=2"

    $arr = unserialize($_REQUEST["item"]); 
    foreach($arr as $index => $position)
    {
        //Do what you want
    }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM