CI_Parser Class Reference

List of all members.


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

Detailed Description

Definition at line 27 of file Parser.php.


Member Function Documentation

CI_Parser::_match_pair ( string,
variable 
)

Matches a variable pair.

private

Parameters:
string 
string 
Returns:
mixed

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         }

Here is the caller graph for this function:

CI_Parser::_parse_pair ( variable,
data,
string 
)

Parse a tag pair.

Parses tag pairs: {some_tag} string... {/some_tag}

private

Parameters:
string 
array 
string 
Returns:
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         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_Parser::_parse_single ( key,
val,
string 
)

Parse a single key/value.

private

Parameters:
string 
string 
string 
Returns:
string

Definition at line 102 of file Parser.php.

Referenced by _parse_pair(), and parse().

00103         {
00104                 return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
00105         }

Here is the caller graph for this function:

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

Parameters:
string 
array 
bool 
Returns:
string

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         }

Here is the call graph for this function:

CI_Parser::set_delimiters ( l = '{',
r = '}' 
)

Set the left/right variable delimiters.

public

Parameters:
string 
string 
Returns:
void

Definition at line 85 of file Parser.php.

00085                                       {', $r = '}')
00086         {
00087                 $this->l_delim = $l;
00088                 $this->r_delim = $r;
00089         }


Member Data Documentation

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.


The documentation for this class was generated from the following file: