[eluser]steel_slasher[/eluser]
I am working on a CMS and I have made a parser for an array which contains details on where to get data for a template. The library which parses the array will load a model or library and then call a function which is required to retrieve the information.
The array for the parser:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['main'] = array(
array(
'block'=>'text',
'type' => 'static',
'title' => 'First piece of text',
'content' => 'Second piece of text'
),
array(
'block'=>'text',
'type' => 'static',
'title' => 'Third piece of text',
'content' => 'Fourth piece of text'
),
array(
'block'=>'text',
'type' => 'static',
'title' => 'Fifth piece of text',
'content' => 'Sixth piece of text'
),
array(
'fauxvar' => 'news',
'file'=>'news',
'type' => 'dynamic',
'class' => 'model',
'title' => 'headlines()',
'content' => 'frontpage()'
)
)
?>
The actual parser itself:
Code:
function content($controller)
{
$this->CI =&get;_instance();
$mainobject = '$this';
$data = array();
$config = $this->CI->load->controller_config($controller);
if(is_array($config['main']))
{
log_message('Debug', 'Controller config is array');
for($i=0;$i<count($config['main']);$i++)
{
if($config['main'][$i]['type'] == 'static')
{
$data[$config['main'][$i]['block']][] = $config['main'][$i];
}
if($config['main'][$i]['type'] == 'dynamic')
{
if($config['main'][$i]['class'] == 'model')
{
$this->CI->load->model($config['main'][$i]['file']);
log_message('DEBUG','Model loaded, from array!');
}
if(isset($config['main'][$i]['title']))
{
$class = strtolower($config['main'][$i]['file']);
call_user_func(array(&$this->CI->{$class},$config['main'][$i]['title']));
//Alternate doesn't work either
$this->CI->{$class}->{$config['main'][$i]['title']};
}
/*Ignore
if(isset($config['main'][$i]['content']))
{
$titles = call_user_func(array(&$this->CI->$config['main'][$i]['file'], $config['main'][$i]['title']));
}*/
}
}
}
return $data;
}