数组到字符串转换,来自下拉表单

时间:2016-11-27 04:09:33

标签: php codeigniter parameters dropdown

我对PHP比较新。我得到了以下错误,即使我看到许多重复的问题与功能参数相关的答案,我也无法弄清楚如何解决这个问题:

  

遇到PHP错误

     

严重性:注意

     

消息:数组到字符串转换

     

文件名:helpers / form_helper.php

     

行号:304

这是代码,您可以看到评论旁边的第304行:

if ( ! function_exists('form_dropdown'))
{
    function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
    {
        if ( ! is_array($selected))
        {
            $selected = array($selected);
        }

        if (count($selected) === 0)
        {
            if (isset($_POST[$name]))
            {
                $selected = array($_POST[$name]);
            }
        }

        if ($extra != '') $extra = ' '.$extra;  //Line Number: 304

        $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';

        $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";

        foreach ($options as $key => $val)
        {
            $key = (string) $key;

            if (is_array($val))
            {
                $form .= '<optgroup label="'.$key.'">'."\n";

                foreach ($val as $optgroup_key => $optgroup_val)
                {
                    $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';

                    $form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
                }

                $form .= '</optgroup>'."\n";
            }
            else
            {
                $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';

                $form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
            }
        }

        $form .= '</select>';

        return $form;
    }
}

这是一个提供一些值的代码:

    $config['field']['activation_method'] = array('type'=>'dropdown','params'=>array('options'=>array('none'=>$this->lang->line('preference_field_activation_method_none'),'email'=>$this->lang->line('preference_field_activation_method_email'),'admin'=>$this->lang->line('preference_field_activation_method_admin'))));

然后对调用form_dropdown函数的代码的引用如下:

function _field_dropdown($key)
{
    $options = $this->field[$key]['params']['options'];
    unset($this->field[$key]['params']['options']);
    return form_dropdown($key,$options,$this->CI->validation->{$key},$this->field[$key]['params']);
}

0 个答案:

没有答案