DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Carlos has posted 1 posts at DZone. View Full User Profile

Using Module_parse Like Module_view In Code Igniter Using Matchbox

06.22.2009
| 3937 views |
  • submit to reddit
        // Updating Matchbox for use Parser as the same easy way to use module_view
//
// I only made a extension as copy paste from original parse method

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/** insert phpdoc here */

/**
 * My Parser Class
 *
 * @package		Matchbox
 * @author		Ninetails
 * @link		http://codeigniter.com/user_guide/libraries/parser.html
 */
class MY_Parser extends CI_Parser {
	/**
	 *  Parse a template
	 *
	 * Parses pseudo-variables contained in the specified template,
	 * replacing them with the data in the second param
	 *
	 * @access	public
	 * @param	string
	 * @param	array
	 * @param	bool
	 * @return	string
	 */
	function module_parse($module, $template, $data, $return = FALSE)
	{
		$CI =& get_instance();
		$template = $CI->load->module_view($module, $template, $data, TRUE);
		
		if ($template == '')
		{
			return FALSE;
		}
		
		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 ($return == FALSE)
		{
			$CI->output->append_output($template);
		}
		
		return $template;
	}
}
// END Parser Class

/* End of file MY_Parser.php */
/* Location: ./system/libraries/application/MY_Parser.php */