Please Review

Discussion in 'PHP' started by imphpguru, Nov 8, 2008.

  1. #1
    Hi,
    I have just finished my latest post on PHP. I was looking for a review from my fellow PHP programmers. Can you please give me a review / comments on the blog post? The post is linked as my latest post, so it shouldnt be a problem for you guys to locate. Anyhows, I will give it here also.. http://loveofphp.com/from-the-author/template-system-complete-tutorial-the-labour-part.html. Please tell me what do you think about this one!!

    Thanks

    imphpguru
     
    imphpguru, Nov 8, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Why not posting the whole post here? :D

    b.t.w for your template class

    note that this is more beautiful

    class template {
    // code
    }

    instead of
    class template
    ....{
    ....//code
    ....}

    :)
     
    EricBruggema, Nov 9, 2008 IP
  3. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Dude.. You have to look at your syntax...

    Should be more like
    
    function template($template_file,$template_vars= array(),$template_path=""){
    	$this->contents = $this->getTemplate($template_file,$template_path);
    	$this->template_vars = $template_vars;
    	$this->template_path = $template_path;
    }
    
    function getTemplate($template_file,$template_path = ""){
    	$txt = substr($template_path,strlen($template_path) - 1,1);
    	if(($txt != "/") && ($txt != "\\") && ($txt != "")){
    		$template_path = $template_path."/";
    	}
    
    	// PHP 5 Method
    	if(function_exists("file_get_contents")){
    		$full_path = $template_path.$template_file;
    		$contents = @file_get_contents($full_path);
    	}else{ // Traditional Method
    		$f = fopen($template_file,"r");
    		$contents = fread($f,filesize($template_file));
    	}
    	return $contents;
    }
    PHP:
    Your code is well-described, so it's only the syntax you gotta look at :)
     
    elias_sorensen, Nov 9, 2008 IP
  4. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Hi,
    Yeah I am working on a more PEARy version of it.. but I have had a habit of writing code this ways... Am improving. This was written about 4 months ago :D. Also, putting the post here... once again.. google duplicate content :D.

    Thanks

    imphpguru :).
     
    imphpguru, Nov 9, 2008 IP