[eluser]mlage[/eluser]
Okay. I have gone through the code and rewritten a good chunk. Fixed all php errors and some logic errors. I decided to change the makeTemplate() method into two methods. There is still the makeTemplate() method but now, inside it, I call recursiveParse() method. Here lies my problem... it isn't working very well.
I finished rewriting my comments to work with a phpdocument parser ... so here is the documentation and source code:
My Online Documentation
Again, the two links I provided in my first post of this thread to the actual code files have been updated to reflect my changes if you want to read the whole updated code...
Folder of the skeleton file and other view files
Error: Nothing is outputted
So if anyone knows about tokens [strtok()], and recursion and has some time, can you please give a look over the code...
Here is the call in the makeTemplate() function:
Code:
$token = strtok( $skeleton, "{" ); //<!DOC...xhtml">
$tmp = "";
$this->output .= $this->recursiveParse($token, $tmp);
Here is recursiveParse():
Code:
function recursiveParse ( $token, $tmp ) {
if($token !== FALSE) {
$tmp .= $token;
//Keep Trucking
$token = strtok( ":" ); //find out view-variable type
switch($token) {
case 's':
//parse into {variableName}
$token = strtok( "}" );
$tmp .= "{".$token."}";
break;
case 'v':
//grab this views contents and parse it while loading it
$token = strtok ( "}" );
$str = file_get_contents( "system/tmp/".$this->templateName."/".$token.".html" );
$token = strtok( $str, "{" );
if ($token !== FALSE) {
$tmp .= $this->recursiveParse($token, $tmp);
}
else
{
return $tmp;
}
break;
case 'd':
//use dData array to parse dynamic data
$token = strtok( "}" );
$tmp .= $this->dData[$token]; //v0.0.5 if dData($token) doesn't exist... must catch error
break;
default:
//error probably...
$key = $token;
$token = strtok( "}" );
$tmp .= "{".$key.":Invalid View-Variable Type}";
}
$token = strtok("{");
$tmp .= $this->recursiveParse($token, $tmp);
}
else
{
//Done, update output with tmp
return $tmp;
}
}
Here is my controller that I'm getting my error on:
Code:
class Test extends Controller {
var $dData = array();
var $sData = array();
//Constructor
function Test()
{
parent::Controller();
//$this->dData = new array()
//$this->sData = new array();
if ( $this->session->userdata('loggedIn') == TRUE)
{ //Status: Logged In
$this->sData['groupId'] = 1;
$this->sData['username'] = $this->session->userdata('username');
}
else
{
$this->sData['groupId'] = 0;
$this->sData['username'] = "Guest";
$array_items = array('userId' => 0, 'username' => 'Guest', 'email' => '', 'loggedIn' => FALSE);
$this->session->set_userdata($array_items);
}
}
//Index Page
function index() // index.php/home/index or index.php/home or index.php (since Home class is default Controller)
{
$template = array( 'name' => 'gh' );
$this->load->library( 'LAGE_Templater', $template);
if ( $this->sData['groupId'] > 0 ) //Logged In
{
//logout link array
$this->dData['authLink'] = "<a href='#'>Log Out</a>";
}
else
{
$this->dData['authLink'] = "<a href='#'>Log In</a>";
}
$this->dData['pageTitle'] = "LageCMS v0.0.4 SandBox";
$this->dData['contentTitle'] = "h1 block - Lage";
$this->dData['contentData'] = "<p>bla bla bla, content ... content... content...</p>";
$this->lage_templater->addData($this->dData);
$this->lage_templater->makeTemplate( $this->sData );
$this->lage_templater->output();
}
}
Any help? Guidance? Any input and I will be happy
Update: Added link to my documentation to help others who are interested in helping me