Welcome Guest, Not a member yet? Register   Sign In
Need help with Template/Cache Libraries that I wrote...
#1

[eluser]mlage[/eluser]
Hello everyone! I wanted to write a nifty template/cache engine for this framework (and of course, my personal use) and I have finished writing the first version of the code but every time I try to use it, I get blank pages sent to me without any PHP errors.

I have checked the configuration, PHP errors are set on. I'm running Apache2, PHP 5, the latest of most modules on an Apache Server on my personal Ubuntu machine at home...

Full Documentation and source code viewable here:
My Online Documentation

I have setup in the main config that personal libraries are "LAGE_". Session and the appropriate libraries in use are auto-loaded... I just don't get why I don't get errors from PHP... just a blank page... I was hoping someone with a fresh perspective could see what I easily did wrong and lead me in the right direction for debugging...

An example of the controller that gives me a blank page:
Code:
class Test extends Controller {

    private var $dData;
    private var $sData;
    
    //Constructor
    function Test()
    {
            parent::Controller();
            $this->dData = array()
            $this->sData = 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)
    {
        $CI->load->library( 'templater', "gh" );
        /*
            Skeleton
            {v:head}
                {d:pageTitle}
            {v:mainNav}
            {d:contentTitle}
            <p>Username: {s:username} - {d:authLink} (logout/login)</p>
            {d:contentData}
            {v:footer}
        */
            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>" );
        
        $CI->templater->addData($this->dData);
        $CI->templater->makeTemplate( $sData );
        $CI->templater->output();
    }
}

File Structure:
LageCMS/index.php
LageCMS/system/application/libraries/ the two libraries
LageCMS/system/application/controllers/test.php
LageCMS/system/gh/ skeleton.html and all necessary views (footer.html, head.html, mainNav.html)

Does anyone know for some debugging techniques in CI? Like if I can setup "break" points with a debug class or something to analyze the data as it flows through the program? Any help is greatly appreciated!!!!
#2

[eluser]WanWizard[/eluser]
Are you sure error reporting is set to E_ALL, and display errors is on in php.ini?

Because you're using $CI in your index method, which isn't defined anywhere, and therefore a PHP error that should have been displayed.
#3

[eluser]mlage[/eluser]
@WamWizard: Thank you!! I had to update the php.ini settings and now I'm getting errors Smile Now to work through the errors... then when I get this version running, I'm going to implement a recursive solution for the "makeTemplate()" method to allow unlimited "sub-views" with parsable data Smile

Right now its setup so that only views in the "skeleton" can have sub-views... but we both know that a recursive solution could easily do infinite views in a tree like structure Smile

I'll post an update to the code when I get it working Smile

THANK YOU!!!!

P.S. Fixed the reference to the undefined $CI object...woopsies... I was to caught up in programming in the library that I forgot that the controller's $this reference was all I needed...

P.S.S. I love your avatar... HAHAHA
#4

[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 Smile

Update: Added link to my documentation to help others who are interested in helping me Smile




Theme © iAndrew 2016 - Forum software by © MyBB