Welcome Guest, Not a member yet? Register   Sign In
objects in the template parser
#1

[eluser]heavenquake[/eluser]
In the template parser's parse() method you will find this:
Code:
foreach ($data as $key => $val)
        {
            if (is_array($val))
            {
                $template = $this->_parse_pair($key, $val, $template);        
            }
            else
            {
                $template = $this->_parse_single($key, (string)$val, $template);
            }
        }
if $val is an object, it erroneously get's treated as a string, which will give errors, while it should just treat it as an array.

the fix is to add a check for objects in the same line. I tested, the rest of the code runs great this way without glitches.

Code:
foreach ($data as $key => $val)
        {
            if (is_array($val) || is_object($val))
            {
                $template = $this->_parse_pair($key, $val, $template);        
            }
            else
            {
                $template = $this->_parse_single($key, (string)$val, $template);
            }
        }

you will also need to update the _parse_pair method in order to recurse correctly
Code:
foreach ($row as $key => $val)
            {
                if ( ! is_array($val) && ! is_object)
                {
                    $temp = $this->_parse_single($key, $val, $temp);
                }
                else
                {
                    $temp = $this->_parse_pair($key, $val, $temp);
                }
            }
#2

[eluser]heavenquake[/eluser]
Another possible solution which might be more consistent with the approach used in views could be to deploy _ci_object_to_array($val) on the value just before the type-check. Like the following:

Code:
foreach ($row as $key => $val)
{
   $val = $CI->load->_ci_object_to_array($val);
   if ( ! is_array($val))
   {
      $temp = $this->_parse_single($key, $val, $temp);
   }
   else
   {
      $temp = $this->_parse_pair($key, $val, $temp);
   }
}




Theme © iAndrew 2016 - Forum software by © MyBB