SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 65 of 65
  1. #51
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    People really do think templates should have NO logic, I disagree, they can have a ton of logic, so long as it is all of it has to do with presentation logic, and not business logic.
    What templates do you mean Smarty??? In this case I see no differences between PHP "if" and Smarty "if". If you meant PHP you pointed out my problem. I think PHOP code in the templates is a bad thing, HTML code in the PHP function is bad too.

    In the ASP.NET you can easily append data to the table, probably we should try Odan, it's a ASP.NET port on PHP.

  2. #52
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    explain...

    And explain to me how what you see there isn't an exact rip of JSTL and Struts. Point is, if you are going to talk about ASP.NET, remember what came first, JavaBeans.

    However, I do agree it looks good, regardless of where the ideas come from. The problem I have with Odan is that it can't be a port of ASP.NET unless ASP.NET isn't object oriented.

  3. #53
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's easy to get confused about PHP / (ASP).NET "portability".

    For me the first and very worthwhile step is to have a PHP template parser which can read templates written for ASP.NET. It doesn't need to come with a complete class library "mimicking" the .NET library - users of the template engine can make their own classes to start with.

    The point is being able to take an ASP.NET template, as created by VS for example, and be able to use it in a PHP environment. Then we can say "Thanks MS for the nice GUI - now for some PHP".

    Good news is they're working on this in PEAR: http://pear.php.net/package-info.php?pacid=111 this uses the tokenizer extension to parse templates, rather than regexes and;

    do things like ASP.net or Cold Fusion tags.
    and

    Targeted at Object based systems - default behavior is to display object variables
    Marvellous

  4. #54
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
      <head>
        <title>{title}</title>
      </head>
      <body>
      <H1>{title}</H1>
        <form name="form">
        <table>
          <tr>
            <td>
              Input Box: <input name="input">
            </td>
          </tr>
          
          <!-- note here the use for foreach as an attribute value -->
          
          <tr foreach="numbers,number,string">
            <td>
              <a href="mypage.html?id=%7Bnumber%7D">{string}</a>
            </td>
          </tr>
          
          
        </table>
      </body>
    </html>
    I like the look of that Harry, thanks for pointing it out

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #55
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Been following this post as much as possible and it's becoming interesting reading.

    But I'm still waiting on a reply from my earlier post. I now understand the fact that seperating logic/presentation layers goes beyond seperating PHP from markup.

    Though does not the methods I have choosen acheive this ?

  6. #56
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Harry,

    Have you tried using HTML_Template_Flexy yet?

    If so, what do you think?

  7. #57
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post XSL

    Well, to use XSL I should have XML file. But my data is stored in MySQL database, so I have to make SQL query, then create XML file and only then print it. It seem to be slow, though the results of the queres can be stored in XML file, so I shan't have to make queries again.

  8. #58
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mika - Can you not do what I did ?

    I have the static XML file holding the content that doesn't change, then I grab this file, putting the content (from database for example) into this file, wrapped in allowable tags where required, i.e. to show log files, page results etc.

    I still believe that using XML/XSLT is the better option, since the generated XML holding the database content intact (or anyother XML file for that matter) can be transformed into various formats for the web.

    It's not that difficult - though at the moment, I can't release the classes I've written - shame really, as I think other forum members would benifit from this method.

  9. #59
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    clear

    Dr Livingston, I believe that we are all very clear on your method. I think that our viewpoints on XSLT have been clearly stated. At least for me they are

    1. Yes, XSLT is a nice template language for translating an XML file
    2. You populate XML from the data to generate XSLT because the data is not stored in XML

    I personal see that as an unneccesary indirection. But again, these are personal opinions. My point is, without introducing code, you just keep saying the same thing over and over like no one hears you. We hear you, I promise. We think your ideas are good and I am sure people have played with them. But if you cannot release code, then stop posting the same thing over and over again.

    I appreciate your contribution, I am not criticizing that your ideas work if someone is willing to accept that layer of indirection. Just stating that your posts seem to repeat themselves without any new information.

  10. #60
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry all - wasn't too sure if anyone was actually listening that's all. I will proberly get butchered for this, but here is a development version of what I have so far.

    First, the xslt file. Understand my knowledge of xslt is limited - I'm still learning this one:

    PHP Code:
    <?xml version='1.0' encoding='utf-8'?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method='html' cdata-section-elements="cdata" version='1.0' encoding='utf-8' indent='yes' />

    <!-- string formatting -->

    <xsl:template match='br'>
        <br />
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match='bold'>
        <b>
        <xsl:value-of select='.' /></b>
    </xsl:template>

    <xsl:template match='italic'>
        <i>
        <xsl:value-of select='.' /></i>
    </xsl:template>

    <xsl:template match='underline'>
        <u>
        <xsl:value-of select='.' /></u>
    </xsl:template>

    <xsl:template match='para'>
        <p>
        <xsl:value-of select='.' /></p>
    </xsl:template>

    <!-- FORMs -->

    <xsl:template match='form'>
        <form>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:attribute name='method'><xsl:value-of select='@method' /></xsl:attribute>
        <xsl:attribute name='action'><xsl:value-of select='@action' /></xsl:attribute>
        <xsl:apply-templates />
        </form>
    </xsl:template>

    <xsl:template match='text'>
        <input type='text'>
        <xsl:attribute name='value'>
            <xsl:value-of select='.' />
        </xsl:attribute>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:attribute name='size'><xsl:value-of select='@size' /></xsl:attribute>
        <xsl:attribute name='maxlength'><xsl:value-of select='@maxlength' /></xsl:attribute>
        </input>
    </xsl:template>

    <xsl:template match='password'>
        <input type='password'>
        <xsl:attribute name='value'>
            <xsl:value-of select='.' /></xsl:attribute>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:attribute name='size'><xsl:value-of select='@size' /></xsl:attribute>
        <xsl:attribute name='maxlength'><xsl:value-of select='@maxlength' /></xsl:attribute>
        </input>
    </xsl:template>

    <xsl:template match='hidden'>
        <input type='hidden'>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:attribute name='value'><xsl:value-of select='@value' /></xsl:attribute>
        </input>
    </xsl:template>

    <xsl:template match='submit'>
        <input type='submit'>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:attribute name='value'><xsl:value-of select='@value' /></xsl:attribute>
        </input>
    </xsl:template>


    <xsl:template match='select'>
        <select>
        <xsl:attribute name='size'><xsl:value-of select='@size' /></xsl:attribute>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:apply-templates /></select>
    </xsl:template>

    <xsl:template match='option'>
        <option>
        <xsl:attribute name='value'><xsl:value-of select='@value' /></xsl:attribute>
        <xsl:apply-templates /></option>
    </xsl:template>

    <xsl:template match='textarea'>
        <textarea>
        <xsl:attribute name='name'><xsl:value-of select='@name' /></xsl:attribute>
        <xsl:attribute name='cols'><xsl:value-of select='@cols' /></xsl:attribute>
        <xsl:attribute name='rows'><xsl:value-of select='@rows' /></xsl:attribute>
        <xsl:apply-templates /></textarea>
    </xsl:template>

    <!-- ANCHORs -->

    <xsl:template match = "link">
         <a>
          <xsl:attribute name="href">
            <xsl:value-of select = "@href" />
        </xsl:attribute>
          <xsl:value-of select="." />
        </a>
    </xsl:template>

    <!-- BUTTONs -->

    <xsl:template match='button-row'>
            <tr>
            <td width='100%' align='center' height='48' valign='center'>
                <xsl:apply-templates />
            </td></tr>
    </xsl:template>

    <xsl:template match='cancel-button'>
        <button onClick='window.location="index.php";'>
        <xsl:attribute name='onclick'><xsl:value-of select='@onclick' /></xsl:attribute>
            <xsl:value-of select='.' /></button>
    </xsl:template>

    <xsl:template match='go-button'>
        <button>
            <xsl:attribute name='onClick'><xsl:value-of select='@onClick' /></xsl:attribute>
            <xsl:value-of select='.' /></button>
    </xsl:template>
            
    <!-- TABLE cell outputs -->

    <xsl:template match='table'>
        <tr>
        <td width='100%' valign='top'>
            <table border='0' align='center' cellspacing='1' cellpadding='0'>
            <xsl:attribute name='width'><xsl:value-of select='@width' /></xsl:attribute>
            <xsl:attribute name='bgcolor'><xsl:value-of select='@bgcolor' /></xsl:attribute>
            <tbody>
            <xsl:apply-templates />
            </tbody></table>
        </td></tr>
    </xsl:template>

    <xsl:template match='alt-table'>
        <tr>
        <td width='100%' valign='top'>
            <table border='0' style='border:solid 1px black;' width='512' align='center' cellspacing='1' cellpadding='0'>
            <xsl:attribute name='width'><xsl:value-of select='@width' /></xsl:attribute>
            <xsl:attribute name='bgcolor'><xsl:value-of select='@bgcolor' /></xsl:attribute>
            <tbody>
            <xsl:apply-templates />
            </tbody></table>
        </td></tr>
    </xsl:template>

    <xsl:template match='row'>
        <tr>
        <xsl:for-each select='cell'>
            <td>
                <xsl:attribute name='align'><xsl:value-of select='@align' /></xsl:attribute>
                <xsl:attribute name='valign'><xsl:value-of select='@valign' /></xsl:attribute>
                <xsl:attribute name='width'><xsl:value-of select='@width' /></xsl:attribute>
                <xsl:attribute name='height'><xsl:value-of select='@height' /></xsl:attribute>
                <xsl:attribute name='bgcolor'><xsl:value-of select='@bgcolor' /></xsl:attribute>
            <xsl:apply-templates />
            </td>
        </xsl:for-each>
        </tr>
    </xsl:template>

    <xsl:template match='title'>
        <tr>
        <td width='100%' align='center' height='24' valign='top'>
            <xsl:apply-templates /></td></tr>
    </xsl:template>

    <xsl:template match='message'>
        <tr>
        <td width='100%' align='center' height='16' valign='center'>
        <xsl:attribute name='colspan'><xsl:value-of select='@colspan' /></xsl:attribute>
            <xsl:apply-templates /></td></tr>
    </xsl:template>

    <xsl:template match='message-block'>
        <tr>
        <td width='100%' align='center' height='32' valign='center'>
            <xsl:apply-templates /></td></tr>
    </xsl:template>

    <xsl:template match='spacer'>
        <tr>
        <td width='100%' align='center' height='16' valign='center'>
            <xsl:attribute name='colspan'><xsl:value-of select='@colspan' /></xsl:attribute>
            </td></tr>
    </xsl:template>

    <xsl:template match='content'>
        <tr>
        <td width='100%' align='center' height='16' valign='center'>
            <xsl:apply-templates /></td></tr>
    </xsl:template>
    </xsl:stylesheet>
    And now some example xml files I use:

    PHP Code:
    <root>
        <
    title>
            <
    bold>Manage Employee's</bold>
        </title>
        <message>You may use the Quick Search facility below to manage an employee.</message>
        <spacer />
        <content>
            [ <link href='
    index.php?Do=UserSearch&amp;chr=A'>A</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=B'>B</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=C'>C</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=D'>D</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=E'>E</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=F'>F</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=G'>G</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=H'>H</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=I'>I</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=J'>J</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=K'>K</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=L'>L</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=M'>M</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=N'>N</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=O'>O</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=P'>P</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=Q'>Q</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=R'>R</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=S'>S</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=T'>T</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=U'>U</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=V'>V</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=W'>W</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=X'>X</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=Y'>Y</link> |
            <link href='
    index.php?Do=UserSearch&amp;chr=Z'>Z</link> ]
        </content>
        <button-row>
            <go-button onClick='
    window.location="index.php?Do=AddUser";'>New Employee</go-button>
        </button-row>
        <table width='
    448' bgcolor='skyblue'>
            <import />
        </table>
        <spacer />
    </root> 
    And now for the classes:

    PHP Code:
    class db_connect extends file_handle
        {
            
            /*
            class properties
            */
            var $hostname;
            var $username;
            var $password;
            
            var $srce; 
            var $numb;
            var $q;
            
            /*
            class constructor
            */
            function db_connect($srce = "", $hostname = "", $username = "", $password = "")
            {
                $this     -> host     = $hostname;    /* database server hostname */
                $this     -> user     = $username;    /* database server username */
                $this     -> pass     = $password;    /* database server password */
                
                $this     -> srce     = $srce;        /* (database) query source */
            }
            
            /*
            class function 
            
            query database table passed to class function
            */
            function query_user_db($query)
            {
                $conn     = @ mysql_connect($this -> host, $this -> user, $this -> pass);
                $stmt     = @ mysql_select_db($this -> srce, $conn);
                
                if($conn && $stmt)
                {
                    /* no given errors from database connection */
                    $q     = @ mysql_query($query, $conn);
                    $this     -> numb     = @ mysql_num_rows($q);
                    
                    /** added 04 01 03 **/
                    
                    $this     -> fields    = @ mysql_num_fields($q);
                    $this     -> q = $q;
                    
                    return $q;
                }
                else
                {
                    /* something went wrong with database connection */
                    if(LOG_DB_ERRORS)
                    {
                        ?>
                        <div class="smaller">** Database Error **</div>
                        <?
                        $str 
    date("Y-m-d H:i:s")." - [ Database Error on file: ".$_SERVER["REDIRECT_URL"]." ]\r\n";
                        
    $this -> append_txt2_file("error-log.txt"$str);
                        exit();
                    }
                }
            }
            
            
    /**
             * class member function
             * public
             *
             * set database source
             */
            
    function set_db_source($source)
            {
                
    $this -> srce $source;
            }
            
            
    /*
            class function
            
            return number of records found from last known database query
            */
            
    function total_rows_db()
            {
                return 
    $this     -> numb;
            }
            
            
    /*
            class functon added 04 01 03
            
            return number of fields given by query string
            */
            
    function total_fields_db()
            {
                return 
    $this -> fields;
            }
            
            
    /*
            class function added 04 01 03
            
            return an 2 dimensional array of db query 
                array[rec][field]
                array[rec][field]...
            */
            
    function dump_user_db($query "")
            {
                
    /**
                 * can also carry out the database query from here
                 * if needs be 
                 */
                
    if(isset($query) && $query != (string) "")
                {
                    
    $this -> query_user_db($query);
                }
                
                
    $count 0;
                
                while(
    $r mysql_fetch_row($this -> q))
                {
                    
    $limit $this -> fields;
                    
                    for(
    $a 0;$a $limit;$a++)
                    {
                        
    $array[$count][$a] = $r[$a];    
                    }
                    
    $count++;
                }
                return 
    $array;
            }
            
        } 
    /* end of class db_connect */
        
        /**
         * php class number 04
         *
         * maintain file read, write, delete
         *
         *
         * example of use:
         *
         */
        
    class file_handle
        
    {
        
            
    /*
            class properties
            */
            
    var $fp;
            var 
    $filename;
            
            
    /*
            class function
            
            append a character string to specified text file
            */
            
    function append_txt2_file($filename$string)
            {
                if(
    $fp fopen($filename"a+"))
                {
                    
    fputs($fp$string);
                    
    fclose($fp);
                }
            }
            
        } 
    /* end of class file_handle */

    class DocReader 
        

            var 
    $string
            var 
    $type;   
            var 
    $bignum 1000000;
            var 
    $uri

            function 
    DocReader($uri
            {                                                  
                
    $this -> SetUri($uri); 
                
    $this -> uri $uri;
                
    $this -> SetType(); 

                
    $fp fopen($this -> GetUri(), "r"); 
                
                if(
    $fp
                {                                       
                    if(
    $this -> GetType() == 'file'
                    { 
                        
    $length filesize($this -> GetUri()); 
                    } 
                    else 
                    { 
                        
    $length $this -> bignum
                    } 
                    
                    
    $this -> SetString(fread($fp$length)); 
                    return 
    1
                } 
                else 
                { 
                    return 
    0
                } 
            } 
         
            function 
    IsFile($uri
            {                                                    
                if(
    strstr($uri'http://') == $uri
                { 
                    return 
    false
                } 
                else 
                { 
                    return 
    true
                } 
            }

            function 
    SetUri($string
            { 
                
    $this -> uri $string
            } 
            
            function 
    GetUri() 
            { 
                return 
    $this -> uri
            } 
            
            function 
    SetString($string
            { 
                
    $this -> string $string
            } 
            
            function 
    GetString() 
            { 
              return 
    $this -> string
            } 
            
            function 
    SetType() 
            { 
                if(
    $this -> IsFile($this -> uri)) 
                { 
                    
    $this -> type 'file';
                } 
                else 
                { 
                    
    $this -> type 'url';
                } 
            } 
            
            function 
    GetType() 
            { 
                return 
    $this -> type
            } 
        } 

        class 
    Xslt
        

            var 
    $xsl
            var 
    $xml;
            var 
    $error;
            var 
    $output;

            function 
    Xslt() 
            { 
                
    $this -> processor xslt_create(); 
            } 
     
            function 
    Destroy() 
            { 
                
    xslt_free($this -> processor); 
            } 
         
            function 
    SetOutput($string
            { 
                
    $this -> output $string
            }
            
            function 
    GetOutput() 
            { 
                return 
    $this -> output
            } 

            function 
    SetXmlString($xml
            {
                
    $this -> xml $xml;
                return 
    true;
            }

            function 
    SetXslString($xsl
            {
                
    $this -> xsl $xsl;
                return 
    true;
            }

            function 
    SetXml($uri
            {
                if(
    $doc = new DocReader($uri)) 
                { 
                    
    $this -> xml $doc -> GetString(); 
                    return 
    true
                } 
                else 
                { 
                    
    $this -> SetError("Could not open $xml"); 
                    return 
    false
                } 
            } 
            
            
    /**
             * additional class method made by les quinn 11 feb 2003
             */
            
    function SetXmlString($uri)
            {
                if(
    is_string($uri))
                {
                    
    $this -> xml $uri;
                    
                    return 
    true;
                }
                else
                {
                    
    /**
                     * unknown type
                     */
                    
    $this -> SetError("Unknown data string in $xml");
                    
                    return 
    false;
                }
            }
            
            function 
    SetXsl($uri
            { 
                if(
    $doc = new DocReader($uri)) 
                { 
                    
    $this -> xsl $doc -> GetString(); 
                    return 
    true
                } 
                else 
                { 
                    
    $this -> SetError("Could not open $uri"); 
                    return 
    false
                } 
            }

            function 
    Transform() 
            {
                
    $arguments = array('/_xml' => $this -> xml'/_xsl' => $this -> xsl);
                
                
    $ret xslt_process($this -> processor'arg:/_xml''arg:/_xsl'NULL$arguments);
                
                if(!
    $ret
                {
                    
    $this -> SetError(xslt_error($this -> processor));
                    return 
    false;
                } 
                else 
                {
                    
    $this -> SetOutput($ret); 
                    return 
    true;
                }
            }

            function 
    SetError($string
            { 
                
    $this -> error $string
            } 
            
            function 
    GetError() 
            { 
                return 
    $this -> error
            } 
        } 
    /* end of class Xslt */
        
        /**
        * php class number 07
        */
        
    class transform_xml /** added 18.02.03 by les quinn version 0.35 **/
        
    {
            
    /**
            * class Xslt (and DocReader) from an [url]www.webreference.com[/url] article
            * unknown author(s) or source
            */
            
            /**
            * class properties
            */
            
    var $temp;
            var 
    $xslt_;
            var 
    $xml_dir;
            var 
    $xml_file;
            var 
    $xsl_file;
            
            
    /**
            * class constructor
            */
            
    function transform_xml()
            {
                
    $this -> xslt_ = new Xslt;
            }
            
            
    /**
            * class method
            * set directory path for xml/xsl files
            */
            
    function set_xml_dir($path)
            {
                
    $this -> xml_dir = (string) $path;
            }
            
            
    /**
            * get directory path for xml/xsl files
            */
            
    function get_xml_dir()
            {
                return 
    $this -> xml_dir;
            }
            
            
    /**
            * class method
            * set either xml file or xml string
            */
            
    function set_xml_file($file)
            {
                
    $this -> xml_file = (string) $file;
            }
            
            
    /**
            * class method
            * set xsl file
            */
            
    function set_xsl_file($file)
            {
                
    $this -> xsl_file = (string) $file;
            }
            
            
    /**
            * class method
            * get xml file or xml string
            */
            
    function get_xml_file()
            {
                return 
    $this -> xml_file;
            }
            
            
    /**
            * class method
            * clear string buffer
            */
            
    function set_xml_buffer()
            {
                
    $this -> temp '';
            }
            
            
    /**
            * class method
            * return string buffer
            */
            
    function get_xml_buffer()
            {
                return 
    $this -> temp;
            }
            
            
    /**
            * class method
            * add an xml tag and content to buffer w/out attributes
            */
            
    function add_xmltag2_buffer($tag$fragment$attr '')
            { 
                
    /**
                * begin to build xml tag
                */
                
    $tmp '';
                
                
    /**
                * check first to see if any attributes available for this tag
                */
                
    if(is_array($attr))
                {
                    
    /**
                    * we have one or more attributes to add to tag
                    */
                    
    foreach($attr as $key => $value)
                    {
                        
    /**
                        * for every attribute found...
                        */
                        
    $tmp .= $key='$value'";
                    }
                }
                
                
    $tmp "<$tag"$tmp .">$fragment</$tag>";
                
    $this -> temp .= $tmp;
            }
            
            
    /**
            * class method
            * enclose an xml string within a pair of specified xml well formed tags
            */
            
    function xml_enclose_tags($tags$fragment)
            {
                
    $str  '<'$tags .'>'$fragment;
                
    $str .= '</'$tags .'>';
                
                
    /**
                * would need to reference this string from object reference, i.e.
                *
                * $obj -> append_text2_xml_string('<tab-import-1 />', $obj -> xml_enclose_tags('tab-row', $xmlFragment)); 
                *
                * where $xmlFragment is the dynamic content embedded within xml tags to use
                */
                
    return $str;
            }
            
            
    /**
            * class method
            * transform a well formed xml file
            */
            
    function make_xml_document()
            {
                
    $this -> xslt_ -> SetXml($this -> xml_dir $this -> xml_file);
                
    $this -> xslt_ -> SetXsl($this -> xml_dir $this -> xsl_file);
                
                if(
    $this -> xslt_ -> Transform())
                {
                    
    /**
                    * echo transformed xml to browser
                    */
                    
    echo($this -> xslt_ -> GetOutput());
                }
                else
                {
                    
    /**
                    * there has been a problem transforming xml file/string
                    */
                    
    echo("Error:"$this -> xslt_ -> GetError());
                }
            }
            
            
    /**
            * class method
            * transform a well formed xml string
            */
            
    function make_xml_string()
            {
                
    $this -> xslt_ -> SetXmlString($this -> xml_file);
                
    $this -> xslt_ -> SetXsl($this -> xml_dir $this -> xsl_file);
                
                if(
    $this -> xslt_ -> Transform())
                {
                    
    /**
                    * echo transformed xml to browser
                    */
                    
    echo($this -> xslt_ -> GetOutput());
                }
                else
                {
                    
    /**
                    * there has been a problem transforming xml file/string
                    */
                    
    echo("Error:"$this -> xslt_ -> GetError());
                }
            }
            
            
    /**
            * class method
            * replace a specified tag with dynamic content from php function
            */
            
    function append_function2_xml_file($tag2parse$function2execute)
            { 
                
    $fp file($this -> xml_dir $this -> xml_file'r');
                
                if(
    $fp)
                {
                    
    $xml_txt '';
                    while(list(
    $num$line) = each($fp))
                    {
                        
    trim($line);
                        
                        
    /**
                        * replace $tag with dynamic content generated by function
                        */
                        
    $xml_txt .= ereg_replace($tag2parse$function2execute($this/* pass on object ref. */$line);
                    }
                }
                
    /**
                * now xml file is retained as an xml string
                */
                
    $this -> xml_file $xml_txt;
            }
            
            
    /**
            * class method
            * continue to replace a specific tag with dynamic content from php string
            */
            
    function append_function2_xml_string($tag2parse$function2execute)
            {
                
    $this -> xml_file ereg_replace($tag2parse$function2execute(), $this -> xml_file);
            }
            
            
    /**
            * class method
            * replace a specified tag with dynamic content from a string
            */
            
    function append_text2_xml_file($tag2parse$text)
            {
                
    $fp file($this -> xml_dir $this -> xml_file'r');
                
                if(
    $fp)
                {
                    
    $xml_txt '';
                    while(list(
    $num$line) = each($fp))
                    {
                        
    trim($line);
                        
                        
    /**
                        * replace $tag with content from $text
                        */
                        
    $xml_txt .= ereg_replace($tag2parse$text$line);
                    }
                }
                
    /**
                * now xml file is retained as an xml string
                */
                
    $this -> xml_file $xml_txt;
            }
            
            
    /** 
            * class method
            * continue to replace a specific tag with dynamic content from a string
            */
            
    function append_text2_xml_string($tag2parse$text)
            {
                
    $this -> xml_file ereg_replace($tag2parse$text$this -> xml_file);
            }
        
        } 
    /* end of class transform_xml */
    Pheww... still with me ?

    Now some PHP to transform that xml file:

    PHP Code:
    function DoExecuteApp($menu$command$executable)
        {
            
    /**
            * create a new instance of transformation class
            */
            
    $trans = new transform_xml;
            
    $XML_DIR '../apps/'$_SESSION["OffManager"]["MenuState"] .'/templates/';
            
            
    /**
            * set xml directory and xsl stylesheet for this application
            */
            
    $trans -> set_xml_dir($XML_DIR);
            
    $trans -> set_xsl_file('admin-.xsl');
                
            
    /**
            * begin TABLE structure
            */
            
    BeginTable('604''top''center');
            
            if(
    strtolower($command) == (string) "home" || empty($command))
            {
                if(
    strtolower($executable) == (string) "usersearch")                        { UserSearch($trans); }
                else if(
    strtolower($executable) == (string) "adduser")                        { AddUser($trans); }
                else if(
    strtolower($executable) == (string) "doadduser")                    { DoAddUser($trans); }
                else
                { 
                    
    $trans -> set_xml_file('admin-home.xml');
                    
    $trans -> append_function2_xml_file('<import />''ShowNumberMessages');
                    
    $trans -> make_xml_string();
                }
            }
            
    /**
            * close TABLE structure
            */
            
    EndTable();
        }

    function 
    ShowNumberMessages($obj '')
        { 
            
    /**
            * functionality for search number of private messages this user has
            */
            
    return $obj -> xml_enclose_tags('message-block''You have <bold>0</bold> new messages today.');
        } 
    Enjoy -

  11. #61
    SitePoint Zealot
    Join Date
    Feb 2003
    Location
    Virginia
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by dnszero
    Disclaimer: I'm thinking out loud here so feel free to tear this up.

    After mulling over the vast range of content in this thread, I've started thinking about how to model the ideal solution for keeping Buisness Logic (BL) and Presentation Logic (PL) seperate. I think your typical web application can be broken down like this:

    Input --> BL Processing --> BL Result Set -->
    PL Processing --> Final Output(HTML)

    ....

    So, I write a script to do this (using resource abstraction and well formated OO PHP ofcourse) everytime the page is called. At the end of my script I have 2 Result Sets in the form of sorted arrays that the developer can now do something with.

    The web designer can put them in a table, he can make an idented list, he put them in a drop down menu or make a map with everything plotted out. And he can change his mind about the which way to do it on a daily basis, and I don't have to change anything.


    To sum it up so far:
    Developing a web site has 2 basic problems with the same structure:
    1) Buisness problem: Input -> Processing -> Output
    2) Presentation problem: Input -> Processing -> Output

    The Buisness problem takes Input from outside the script, does something with it, and produces Output which answers some overall question or problem. The Presentation Problem takes this output, does something to it, and produces HTML which can be rendered by a Brower(the final presentation layer).

    The first problem is solved by the clever use of PHP. At this point, the unanswered question is how to solve the second problem.

    It seems that there are 2 practical ways to handle this, either by using PHP or by using Templates. After following the template debate across multiple threads in various forums, I don't think that they provide the most optimal, long term solution to the problem. Therefore, I will choose to employ some form of PHP to solve the second problem as well.

    Assuming, that the developer has or can be taught at least basic PHP skills, it makes sense to use PHP to answer the Presentation Problem. After all, this is one of the things PHP is designed for. Unfortunately, I don't have any real answers to this part of the equation yet. But I have some vague notions of what the solution might entail when travelling down this path:

    1) Result Sets - by presenting the BL answers this way, it becomes easier to keep the Presentation and Buisness Layers seperate. Also, this can be the basis for a 'contract' between the programmer and the web designer.

    2) PHP is a templating system that can easily handle the above Result Sets. In my example with the list of States and Cities in the form of an array. In the presentation layer, you could pass this Result Set to various functions (objects, whatever) that would display it in various manners, ie,
    <?php $this->displayDropDown($ResultSet);>
    or
    <?php $this->displayOrderedList($ResultSet);?>
    or something along those lines.

    3) As a templating language, PHP is very easy to deal with when you have a special/unique/rare problem, like displaying the above Result Set on a map. You could simply create a function/object/whatever to handle this situation. If it turns out to be something you need often, you add it to the class, otherwise you just add it as you need it. Thereby avoiding the uncontrollable feature creep of things like Smarty (no disrespect intended).



    I gotta run, but lemme know what you think.

    There.. didn't mean to quote your whole post but you had some solid points.

    In regards to the two problems:



    1) Buisness problem: Input -> Processing -> Output
    2) Presentation problem: Input -> Processing -> Output
    The first solution to this puzzle is VERY similar to my own. The second solution is a bit trickier because I too have created a "sand box" if you will for the processed information that came from the Business logic. By creating a "sand box" I protect the internals of my system from any mistakes to get at sensitive Business logic and/or data. From this point I employ a few tactics to create a N-tier presentation logic similar to what HarryR spoke of (nice site by the way).

    I.Since I am using mostly HTML/XHTML I have a simple set of functions that can build repetitive form structures quickly.

    II.I preprocess all business logic into presentation logic BEFORE I let the templates then use that information to PRESENT as the are designed to do. So in essence there should almost never be any LOOPS or complex code in a template only simple structures if not just template data. The reason I say this is because to have these structures in a HTML/XHTML actually takes away a step of the N-tier IMO; though I suspect XML could solve many problems by making a UNIVERSAL standard N-tier step for all. The upside to my solution is that the templates themselves become primitive data types, which can be used over and over again without any STRIPPING of code.

    III.All templates are compiled on the fly right into php code, at which point they can be executed and stored as pure DATA. The beauty of this step is that i can now PIPE the templates/DATA anywhere I want (cache/DB/file) and also output them in any order I want.


    I have a few questions for this astute group.

    Have you taken into consideration a large scale system, that may have multiple modules needing to execute the template system and then having to keep all those structures organized so they can be outputted intact?

    Are your solutions proof of concept of or have you tested them in real world application?

    Lastly, I want to say thanks to all in this post since I've been here for about 2 years and this is the first time I'm have the compunction to post. Good reads!

    PS: I actually downloaded Eclipse today and though it is well formed and elegant in certain places it would get killed in real world application. Funny enough it reminded me of RUBY, all object all the time, which I rather like.

    PSS: I also looked at
    http://pear.php.net/package-info.php?pacid=111
    Very cool.. That concept might actually go into my own engine once I get around to it. Thanks for the link.

    Res

  12. #62
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried using HTML_Template_Flexy yet?
    Nope - just looked at the code. As we're on v 0.3 and I try to be as lazy as possible, will give it a look in a few more minor realeases.

  13. #63
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  14. #64
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good article, and a very good point about using CSS for making a template from a design point of view, but I'd question it's revelance based on the point of view from the actual programming.

    CSS can't for example be used to seperate the mechanics of the logic and presentation layers; i.e. the actual methods of use to represent the logic, i.e. using classes, and the presentation, i.e. using an xml template for example.

    Am I making sense ? I hope so anyways 8)

  15. #65
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you are making sense.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •