Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Html input groups #33

Open
daverdalas opened this issue Feb 2, 2015 · 1 comment
Open

Html input groups #33

daverdalas opened this issue Feb 2, 2015 · 1 comment

Comments

@daverdalas
Copy link

Hey, I have not found a way to bind html input groups.
For example:

$builder->text('group[email]')

I did a little work around but it is not good piece of code :( but you can take a look :)

protected function nameToArray($str)
    {
        if (strpos($str,'[') === false) {
            return $str;
        }
        $re = "/(.*?)\\[(.*?)\\]/"; 
        preg_match_all($re, $str, $matches);
        array_shift($matches);
        $matches = array_filter(call_user_func_array('array_merge', $matches));
        $arr_string = "";
        foreach ($matches as $match)
        {
            $arr_string .= "['{$match}']";
        }
        return $arr_string;
    }
protected function hasModelValue($name)
    {
        if (is_array($this->model))
        {
            $name = $this->nameToArray($name);
            $arr = $this->model;
            eval('$isset = isset($arr'.$name.');');         
            return $isset;
        }
        if (! isset($this->model)) {
            return false;
        }
        return isset($this->model->{$name});
    }
protected function getModelValue($name)
    {
        if (is_array($this->model))
        {
            $name = $this->nameToArray($name);
            $arr = $this->model;
            eval('$val = $arr'.$name.';');  
            return $val;
        }
        return $this->model->{$name};
    }
@adamwathan
Copy link
Owner

Ugh this is a shitty tricky problem. I think your idea of converting everything to a string representation is the way to go. I'm gonna mark this as an enhancement for now, hopefully get a chance to look into it soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants