SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Calling All PHP/MySQL Experts...yes, that means you too. ;)

    I'm taking the week off to brush up on my development skills. I've built a lot of database driven sites, including e-commerce systems etc.

    The biggest bottleneck that is buggin me is every time I work on a back-end system for different clients, for instance, take some code I've written for client x, and later use it on client y's website, I typically have to go back in and do a lot of modification. For instance, adding or changing around MySQL querys, adding fields etc.

    Anyway, I'm going to be honing my PHP OOP skills, however, I was wondering what some of you experts are using.

    I belive that PHP has template support built in, I've also heard of Smarty and FastTemplates, will these help? Could XML possibly be the better advantage.


    Any ideas that you would like to share would be greatly appreciated. I only have about 7 days to brush up on my skills -- try to be come more efficient, before I start on my next clients website.

    Thanks in advance!!

    holmescreek

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess if it's got to that point, it's time to start looking at application frameworks:

    http://www.hotscripts.com/PHP/Script...ion_Framework/

    I can't personally recommend any of those but my own aim (once some other missions are complete) is to get to grips with ezPublish, which is in fact also an application framework, cunningly disguised as a portal.

  3. #3
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP does not have template support built in. It does however have a library of PEAR scripts, one of them is the template script:

    http://pear.php.net/manual/en/packages.templates.php

    There're other templates system like PHPLib, Smarty and FastTemplate which you already mentioned.

    I have my own template, which is fine for normal use, and it's very light weight, it does lack on nested loop capability however.

    PHP Code:
    <?php

    class Template
    {
        var 
    $template;
        var 
    $head;
        var 
    $tail;
        var 
    $vars;

        function 
    Template($template_file)
        {
            global 
    $templates;

            if(!isset(
    $templates[$template_file])) {
                
    $templates[$template_file] = fread(fopen($template_file'r'), filesize($template_file));
            }

            
    $this->template $templates[$template_file];
            
    $this->head '{';
            
    $this->tail '}';
            
    $this->vars = array();
        }


        function 
    tag($head$tail)
        {
            
    $this->head $head;
            
    $this->tail $tail;
        }


        function 
    set($name$value)
        {
            
    $this->template str_replace($this->head.$name.$this->tail$value$this->template);
        }


        function 
    drop($name)
        {
            
    $this->template str_replace($this->head.$name.$this->tail''$this->template);
        }


        function 
    loop($loop_name$array)
        {
            
    $head_pos   strpos(strtolower($this->template), "<!-- loop $loop_name -->") + strlen("<!-- loop $loop_name -->");
            
    $tail_pos   strpos(strtolower($this->template), "<!-- /loop $loop_name -->");
            
    $loop_code  substr($this->template$head_pos$tail_pos $head_pos);
            
    $head_tag   substr($this->template$head_pos strlen("<!-- loop $loop_name -->"), strlen("<!-- loop $loop_name -->"));
            
    $tail_tag   substr($this->template$tail_posstrlen("<!-- /loop $loop_name -->"));

            for (
    $i=0;$i<count($array);$i++) {
                
    $tmp_code $loop_code;
                while (list(
    $k$v) = each($array[$i])) {
                    
    $tmp_code str_replace($this->head.$k.$this->tail$v$tmp_code);
                }
                
    $new_code .= $tmp_code;
            }

            
    $this->template str_replace($head_tag.$loop_code.$tail_tag$new_code$this->template);
        }


        function 
    dropblock($block_name)
        {
            
    $this->template str_replace("<!-- /block $block_name -->""<!-- block $block_name -->"$this->template);
            
    $template explode("<!-- block $block_name -->"$this->template);
            
    $this->template $template[0].$template[2];
        }


        function 
    dump()
        {
            return 
    $this->template;
        }


        function 
    output()
        {
            echo 
    $this->template;
        }
    }

    ?>
    It doesn't use preg_replace, instead of uses str_replace which is considerably faster.

    You can also look into XML/XSLT solution, which PHP supports. You basically create a XSLT template, create XML files and squeeze them together to XHTML and output to browser. SitePoint has an article on this. One of the problem is creating the XML files.

    http://www.php.net/manual/en/function.xslt-process.php

    Here's a sample script:

    PHP Code:
    $xml implode(''file('e:/www/xml/docbook.xml'));
    $xsl implode(''file('e:/www/xml/docbook.xsl'));

    $arguments = array(
         
    '/_xml' => $xml,
         
    '/_xsl' => $xsl
    );

        
    // Create an XSLT processor 
        
    $xh xslt_create();

        
    // Perform the transformation  
        
    $html xslt_process($xh'arg:/_xml''arg:/_xsl'NULL$arguments) or die(xslt_error($xh));

        
    // Destroy the XSLT processor  
        
    xslt_free($xh);

        
    // Output the resulting HTML  
        
    echo $html;
    ?> 
    Work smarter, not harder. -Scrooge McDuck

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As of late, most of the applications I've been developing are based on phpShop Core.

    More info can be found at:
    http://www.phpshop.org/

    The name doesn't depict it but it's actually a web application platform.

    phpShop is a commerce application based on this core framework. Check out the site for more details.

    Thanks,

    Nakia


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •