Public Member Functions | |
| parse ($template, $data, $return=FALSE) | |
| Parse a template. | |
| set_delimiters ($l= '{', $r= '}') | |
| Set the left/right variable delimiters. | |
| _parse_single ($key, $val, $string) | |
| Parse a single key/value. | |
| _parse_pair ($variable, $data, $string) | |
| Parse a tag pair. | |
| _match_pair ($string, $variable) | |
| Matches a variable pair. | |
Public Attributes | |
| $l_delim = '{' | |
| $r_delim = '}' | |
| $object | |
Definition at line 27 of file Parser.php.
| CI_Parser::_match_pair | ( | $ | string, | |
| $ | variable | |||
| ) |
Matches a variable pair.
private
| string | ||
| string |
Definition at line 159 of file Parser.php.
Referenced by _parse_pair().
00160 { 00161 if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) 00162 { 00163 return FALSE; 00164 } 00165 00166 return $match; 00167 }

| CI_Parser::_parse_pair | ( | $ | variable, | |
| $ | data, | |||
| $ | string | |||
| ) |
Parse a tag pair.
Parses tag pairs: {some_tag} string... {/some_tag}
private
| string | ||
| array | ||
| string |
Definition at line 120 of file Parser.php.
References _match_pair(), and _parse_single().
Referenced by parse().
00121 { 00122 if (FALSE === ($match = $this->_match_pair($string, $variable))) 00123 { 00124 return $string; 00125 } 00126 00127 $str = ''; 00128 foreach ($data as $row) 00129 { 00130 $temp = $match['1']; 00131 foreach ($row as $key => $val) 00132 { 00133 if ( ! is_array($val)) 00134 { 00135 $temp = $this->_parse_single($key, $val, $temp); 00136 } 00137 else 00138 { 00139 $temp = $this->_parse_pair($key, $val, $temp); 00140 } 00141 } 00142 00143 $str .= $temp; 00144 } 00145 00146 return str_replace($match['0'], $str, $string); 00147 }


| CI_Parser::_parse_single | ( | $ | key, | |
| $ | val, | |||
| $ | string | |||
| ) |
Parse a single key/value.
private
| string | ||
| string | ||
| string |
Definition at line 102 of file Parser.php.
Referenced by _parse_pair(), and parse().

| CI_Parser::parse | ( | $ | template, | |
| $ | data, | |||
| $ | return = FALSE | |||
| ) |
Parse a template.
Parses pseudo-variables contained in the specified template, replacing them with the data in the second param
public
| string | ||
| array | ||
| bool |
Definition at line 45 of file Parser.php.
References $CI, _parse_pair(), _parse_single(), and get_instance().
00046 { 00047 $CI =& get_instance(); 00048 $template = $CI->load->view($template, $data, TRUE); 00049 00050 if ($template == '') 00051 { 00052 return FALSE; 00053 } 00054 00055 foreach ($data as $key => $val) 00056 { 00057 if (is_array($val)) 00058 { 00059 $template = $this->_parse_pair($key, $val, $template); 00060 } 00061 else 00062 { 00063 $template = $this->_parse_single($key, (string)$val, $template); 00064 } 00065 } 00066 00067 if ($return == FALSE) 00068 { 00069 $CI->output->final_output = $template; 00070 } 00071 00072 return $template; 00073 }

| CI_Parser::set_delimiters | ( | $ | l = '{', |
|
| $ | r = '}' | |||
| ) |
Set the left/right variable delimiters.
public
| string | ||
| string |
Definition at line 85 of file Parser.php.
| CI_Parser::$l_delim = '{' |
Definition at line 29 of file Parser.php.
| CI_Parser::$object |
Definition at line 31 of file Parser.php.
| CI_Parser::$r_delim = '}' |
Definition at line 30 of file Parser.php.