SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 65
  1. #26
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    agree 100%. i don't understand why they have the <?= echo shortcut for short tags but not for the full <?php.

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

    file a bug

    Maybe I should file a bug. In the worst case it will be rejected. If we are lucky, we can get the change in there. We would still have to deal with old versions, but at least the train would be on the right track. I agree that <?= is really a stupid tag. They went through all the trouble of have xml compliance with a processing instruction and then...

    Perhaps when I get a chance I will make a bug out of this.

  3. #28
    SitePoint Enthusiast aivarannamaa's Avatar
    Join Date
    Sep 2002
    Location
    Estonia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it seems normal to have also <?php= but I read from
    http://www.derickrethans.nl/20021230.php
    that PHP developers have considered and rejected this.

  4. #29
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, i read that too. pff!

  5. #30
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While using XHTML, and including the XML tag at the top, you have to use PHP and echo it out like:

    PHP Code:
    echo '<?xml version="1.0"?' . '>';
    BTW.. any good XSLT articles besides Kevin's Im tring to think of the best way for an average user to create template.. wheter I should just let them put in the template, and match it myself, or what.
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  6. #31
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Common sense tells me that even if some next version of Php would support <? $foo ?> then that would be also subject to an ini setting and to hosts installing the latest version etc... So one would have the same compatibility problems.

    The solulution is here and it's easy, if you like it safe, use <?php echo $foo ?>. But if you like it pretty, or if you are lazy (like me) use <?=$foo?>. The worst that can happen is that you might have to do a extented find and replace ('<?=' to '<?php echo ') on all your files before deployment.

    Just another 2-pence (that's 4 so far in this thread )

    And about it being 'nice and proper and brushed off with it's tie straight' xml... Well, I've always liked the Stones better then the Beatles .

    (Guess that's 6 pence now )

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  7. #32
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Zoef
    Common sense tells me that even if some next version of Php would support <? $foo ?> then that would be also subject to an ini setting and to hosts installing the latest version etc... So one would have the same compatibility problems.

    The solulution is here and it's easy, if you like it safe, use <?php echo $foo ?>. But if you like it pretty, or if you are lazy (like me) use <?=$foo?>. The worst that can happen is that you might have to do a extented find and replace ('<?=' to '<?php echo ') on all your files before deployment.

    Just another 2-pence (that's 4 so far in this thread )

    And about it being 'nice and proper and brushed off with it's tie straight' xml... Well, I've always liked the Stones better then the Beatles .

    (Guess that's 6 pence now )

    Rik
    Yeah, then force us people who werent utter moron's to listen to other *lazy* coders ***** becuase PHP is shipped with register_globals off...

    Hey, might as well assume magic_quotes is on as well, since we are too lazy to code for these things.
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  8. #33
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Zaire


    Yeah, then force us people who werent utter moron's to listen to other *lazy* coders ***** becuase PHP is shipped with register_globals off...

    Hey, might as well assume magic_quotes is on as well, since we are too lazy to code for these things.
    Those are probably a bit more serious issues, considering the possible securitity implications. Also there isn't a quick fix for them. So let's not compare aples with pears.

    But like I've said before, it's mostly a matter of preference, and knowing what you're doing. For example, if you have control over the server, you can set it up the way you feel best with, and code accordingly. But if you're writing a script that you want to sell to other developers you better make sure it works on all configurations...

    Just my modest opinions, please feel free to further enlighten me with your views. Nobody's forcing anybody in here.

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  9. #34
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    more on the templating subject:

    http://www.massassi.com/php/articles/template_engines/

    summary: use php as templating language

  10. #35
    "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 agree with that article... And I did write my own template system, and well... it does have its own tags, but it also supports <?php ?> as well.

    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.

    My template engine still has no loop statements, because I loop within the business logic. If a user wanted to loop within a template they could, using actual PHP code, instead of my easy-to-learn template tags, which get interpreted into PHP, stored in a database, then eval()'ed on display.

    My template system has essentially no overhead, aside from a single query on each page to grab the necessary parsed templates for each page.

    Echoing out a variable in my template system is as simple as typing $hello, not <?=$hello?> or <?php echo $hello; ?> or {$hello}... just $hello. I think it's simple and effective.

    I understand pretty much all relavent points stated against template engines, I however believe my system does what I intended from the start, seperating business logic from presentation logic, and on that note... I end my little rant here.
    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.

  11. #36
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Zoef
    Those are probably a bit more serious issues, considering the possible securitity implications. Also there isn't a quick fix for them. So let's not compare aples with pears.

    But like I've said before, it's mostly a matter of preference, and knowing what you're doing. For example, if you have control over the server, you can set it up the way you feel best with, and code accordingly. But if you're writing a script that you want to sell to other developers you better make sure it works on all configurations...

    Just my modest opinions, please feel free to further enlighten me with your views. Nobody's forcing anybody in here.

    Rik
    It's the same issue.. register_globals was nice, easy way to code, that was always around... They decided to drop it's support.. Well, now what happens when they decide to phaze out short_tags becuase of XML? Then what?
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  12. #37
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would question the idea of your template system. You say it seperates logic from presentation ?

    How can it do this is there is even the remotest amount of PHP in the template ? Even if it's only a variable ?

    The option I took, and this is the real seperation of logic from presentation is to use XML and XSLT. Now I can display dynamic content based on an XML format using XSLT.

    And there is absolutely no PHP in sight of the presentation models. That's true layer architecture.

  13. #38
    "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)
    It seperates business logic from presentation logic... either way there is still logic, just a different type.
    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.

  14. #39
    SitePoint Guru
    Join Date
    Oct 2001
    Posts
    656
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would question the idea of your template system. You say it seperates logic from presentation ?
    "separating logic from presentation" is a quote that is used soooo much by people. It is also used sooo wrong because those people do not know what it means.

    Using PHP templates is not about stuffing all your PHP into one file and all HTML with no PHP in it in another file. I read this on the article on massassi.com, and I couldn't say it better:

    The point of templates should be to separate your business logic from your presentation logic, not separate your PHP code from your HTML code.

    A lot of people seem to think that business logic equals PHP code, this is simply not the case. Business logic is logic concerning the data model of an application. It's not even executing a SELECT-query to get content from a database. Most simple PHP applications hardly contain any business logic, as a matter of fact.

    And there is absolutely no PHP in sight of the presentation models. That's true layer architecture.
    . Hehe.. :'( If you'd really understand what layering is about (something I'm still learning myself, but I'd like to think I have a pretty good idea so far), you'd understand that it is not this, as advocated by many PHP 'layering' tutorials:

    - Presentation layer
    Simply stuff your HTML into a template with some ugly syntax and use a template engine

    - Business Layer
    Oh, just stuff the looping and if/else statements needed for that template into the PHP code.

    - Data Layer
    Yay, write your own DB class which acts as a 'magic' database abstraction layer.

    Sorry if this post sounds like I'm a bit pissed, but a lot of people seem to think they are doing "the right thing" when it comes to "layering" their applications (N-tier) and "separating their presentation from business logic", when in fact they're not layering at all (read Vincent's posts on layering on these forums) and they are still mixing their presentation logic with business logic.

    End rant

  15. #40
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think where the crossed purposes are that alot of PHP coders, having taught themself, find themselves with scripts like;

    PHP Code:
    <?php
    if ( $_POST['submit'] ) {
        
    // Mix some "business" logic and data access here
    ?>
    <p>Massive block of HTML here</p>
    <?php
    } else {
        
    // Mix some more "business" logic and data access here
    ?>
    <p>Another massive block of HTML</p>
    <?php
    // Phew!
    ?>
    The most obvious problem is the script is unreadable due to massive blocks of HTML. If these can all be put elsewhere, it's a winner.

    But that's not the point of N-Tier / layering software: the objectives there are many-fold, most of them "-abilities", such as maintainability, scalability, flexibility etc. It just so happens that in layering your application, as a side effect your code may get seperated from HTML but that's not an objective, just a byproduct.

    Likewise I'm still trying to fully understand N-Tier, software layering, patterns and loads more (while being forced to build working apps by day).

    But perhaps this makes it a little clearer (typed fast - probably syntax errors). Here's a shot at explaining a typical PHP script in N-Tier terms;

    PHP Code:
    // Data access
    mysql_connect('host','user','pass');
    // Data access
    mysql_selectdb ('dbname');

    // Business logic
    $sql="SELECT * FROM table";

    // Data access
    $qRes=mysql_fetch_array($sql);

    // Data access? Or presentation logic?
    $tpl=new Template('invoice.tpl');

    // Presentation logic
    $tpl->setLoop('items');

    // Business logic & data access (?)
    while ( $row=mysql_fetch_array($qRes) ) {
        
    // Presentation logic
        
    $tpl->addLoop('items','product_name',$row['product_name'];
        
    // Presentation logic
        
    $tpl->addLoop('items','item_price',$row['price'];

        
    // Presentation logic
        
    $tpl->parseLoop('items');

        
    // Business logic
        
    $total=$total+$row['price'];
    }

    // Presentation logic
    $tpl->setVar('totalPrice',$total);

    // Presentation logic
    echo ( $tpl->parse() ); 
    Note I'm uncertain about what exactly some things are in the above example, in N-Tier terms but for the template stuff (apart from perhaps the act of loading it from a file in the first place) is presentation logic. The template itself may not contain any PHP but here we've still mixed presentation logic with business logic at data access logic.

    The "way" of N-Tier is to break this up so that you have distinct layers where "data access", "business logic" and "presentation logic" take place. Each of layer access the layers below it through a well defined interface - a contract if you like. As long as you obey the contract, you're then in position to start making changes within one layer without breaking others. You probably also minimize the amount of work you have to do.
    Last edited by HarryF; Feb 19, 2003 at 13:59.

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

    Amen

    Captain Proton, Amen! I read that article on the template engine and I have to say it pretty much hits it in the numbers. What the model should deliver to the view is view data. One way to think about presentation data is to view it as 'final'. No more assignments or manipulation should occur in the data presented to the designer. If this is the case, I think you have the presentation idea together.

    For instance, say I give the design an array of models (such as an array of links, each with a 'url', 'title' and 'description').

    The designer might do

    PHP Code:
    <table>
      <?php foreach ($tpl->get('links') as $link) { ?>
      <tr>
        <td><a href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></td>
        <td><?php echo $link['description']; ?></td>
      </tr>
    <?php ?>
    </table>
    While there is "logic", in essence a loop, it is simply for laying it out on the page. If the designer didn't care about the look, he/she could just do

    PHP Code:
    <?php print_r($tpl->get('links')); ?>
    Point is, the data isn't changing, it is merely being translated. I think Captain Proton said it exactly right when he told us not to be afraid of PHP, just to use it to present.

    It is also not a bad think to do conditional logic, if it affect what needs to be displayed. For instance

    PHP Code:
    <?php if ($tpl->has('message')) { ?>
    <div class="message"><?php echo $tpl->get('message'); ?></div>
    <?php ?>
    In short, I think that anything that would belong in a Printer (or LoopManipulator) can surely belong in a template. I believe that a template is just a Loop + Loop Manipulator turned inside out, to give the designer a chance to work with a php layout file instead of a class.

    In rebutal to what HarryF was saying, I went down that road once and realized its shortcomings. Notice that in my business logic (which is not shown, but just prepares the state of these 'final' values) I don't do anything that has to do with presentation, like loops. Loops should never be in business logic. It is silly to prepare a loop in a template class, because you are not sure the designer even wants to use the loop (such as the print_r example). If the designer needs a loop, the designer makes a loop. If you don't want your designer doing any PHP at all, then quit trying to make a dynamic application, it is just part of the game. You can't make dynamic pages without logic in your template. Why? Because certain conditions of some data requires the the wrapper (that stuff that goes around the data, like <div> tags) change state as well. It is not as simple as variable replacement for anything other than the simplest cases. In a serious application, the template must be conditional to be reusable.
    Last edited by mojavelinux; Feb 19, 2003 at 14:30.

  17. #42
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice points you've made, and I agree with you - the example scripts demonstrate your points very well in fact. Though my methods simply don't use tags in the HTML template - there isn't any in fact.

    As I've pointed out, it is using XML. Here is some short script I have for example;

    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($executable) == (string) "usersearch")                        { RunUserSearch($trans); }
            else
            { 
                
    $trans -> set_xml_file('admin-home.xml');
                
    $trans -> append_function2_xml_file('<tab-import />''ShowNumberMessages');
                
    $trans -> make_xml_string();
            } 
    Where pray tell me, is the tags within the HTML ? If I need to change the presentation layer, as you put it, I only need to change the xslt file.

    A designer can tell from the xml file that what something does, such as <title /> and <message /> or <bold /> and <italics /> and <para />.

    They design the page template with xml as per required. For dynamic PHP content, they simply put in a tag for me to look for, i.e. <import /> whereever on the page the content has to go.

    It doesn't matter to the designer what that content is - ratings, comments for the article, a poll, form, etc. That is my job, not the designers.

    No PHP or farting about with variables, etc. One simple tag. The designer in no way has to know PHP. Does this not represent the seperation of presentation and logic ?

  18. #43
    "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)
    While I agree with what most of you are saying, i disagree on some loops, most times I am looping, is a database result, which I don't want in my presentation logic, and has to be in the business logic.
    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.

  19. #44
    "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)
    Originally posted by Dr Livingston
    ...Does this not represent the seperation of presentation and logic ?
    There you said it again... seperation of presentation and logic... There are 2 types of logic, business and presentation.
    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.

  20. #45
    SitePoint Guru
    Join Date
    Oct 2001
    Posts
    656
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Harry, the example you gave is still mixing up business logic with presentation logic. You calculate the total price while also setting up a loop in the template, both in the same loop. The reason why mixing this together this way is a bad thing, is that you cannot reuse the 'logic' for calculating the total outside of that specific part of your code.

    Calculating the total price by summing all the individual prices may be a trivial thing, and it may be tempting to mix this in with the presentation logic. However, this piece of business logic might later be expanded by adding a discount to some products, depending on the number of products a customer has bought, or depending on the day of the week, etc. I'm sure you can imagine that the example you gave will become very complex and unmanagable as the business logic increases in complexity.

    I've taken the liberty to rewrite your example in a way that better separates the layers:
    PHP Code:
    /* Layer 1: Data Access */
    mysql_connect('host','user','pass');
    mysql_selectdb ('dbname');

    // Still data access, no business logic
    $sql="SELECT * FROM table";
    $qRes=mysql_fetch_array($sql);

    /* Layer 2: Business Objects */
    /*
    * Here we set up a 'business object'.
    * The Invoice object (layer 2) only knows about the layer below it (layer 1),
    * which is the query result from the data access layer in this case
    *
    * For this example, Invoice is a simple object with only two methods:
    * getProducts(), which returns an array of product arrays
    * getTotalPrice(), which returns the total price for the products
    */
    $invoice = new Invoice($qRes);

    /* Layer 3: Presentation */
    $tpl=new Template('invoice.tpl');
    $tpl->setLoop('items');

    /*
    * This is where Layer 3 accesses the layer below it, layer 2, and only that layer,
    * to get the products of the invoice.
    */
    foreach ($invoice->getProducts() as $product)
    {        
        
    $tpl->addLoop('items','product_name',$product['product_name'];    
        
    $tpl->addLoop('items','item_price',$product['price'];
        
    $tpl->parseLoop('items');
        
        
    // Notice there's no total calculation here, 
        // this is left to the Invoice object
    }

    /* Still in Layer 3, we access the Invoice object to get the total */
    $tpl->setVar('totalPrice'$invoice->getTotalPrice());

    /* Layer 3 finishes by displaying the template */
    echo ( $tpl->parse() ); 
    Although this is a simple example, the layering is a lot better. In layered software, code in layer n should only access code in the layer below it n-1. In this example, that is the case. A byproduct, or objective depending on your point of view, is that this layering solution allows for true reuse of code. By encapsulating the business logic for calculating the total price of an invoice into an Invoice object, you can reuse this in other parts of your presentation code. This in contrast to calculating the total price inside the presentation logic, which makes it unpossible to reuse this piece of business logic in other presentation layer parts.

  21. #46
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Harry, the example you gave is still mixing up business logic with presentation logic
    Exactly! Was meant as an example to show how PHP is typically coded. And glad you came up with a layered alternative - hopefully we've demonstrated the point.

    One thing I have to discuss though is this;

    PHP Code:
    // Still data access, no business logic
    $sql="SELECT * FROM table"
    See I feel the act of deciding which type of data is required in the job of the business logic. In this example, I think the decision is defined by the query. In a better layered application this would probably be wrapped in data access objects and the business logic decides which object it needs.

  22. #47
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    USA
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)

    Here, Input is just input through whatever means are required. BL Processing is everything your program does to arrive at an answer. BL Result Set is the raw answer. I use the moniker 'Result Set' to mean any group of 1 or more rows made up of 1 or more elements of data.

    Semantics asside, I think that this process is pretty much universal. Basically, given a problem to solve, you take some input, perform an action on it, and produce a raw answer (BL Result Set) to the problem. Next you take the Raw Answer, perform some action on it (PL Processing) and produce your Final Output as HTML.

    From this point of view, I'm first tempted to just generate all of my code programtically. But, should I ever have a developer to work with, that wouldn't be a good solution.

    So, it would seem that the next best place to break this up would be at the Result Set. I can write a PHP script that will take the input, do some dirty deeds (at a reasonable price), and produce an Answer in the form of a Result Set. If this is a complicated problem, then more than likely I will break it into pieces and produce several Result Sets.

    I can then provide some method to pass these Result Sets to the web designer. The designer will process these as he sees fit and he will produce a script of some sort who's final output is HTML.

    So, in solving a problem with this model, the BL and PL are almost completely seperate. As long as both teams agree on the number and form of Result Sets, it doesn't matter how I get there to the web designer and it doesn't matter to me how he presents the final output.

    As an example, say that an ISP wants a website that shows all of the Cities and States that they provide service for, and they want it to be dynamically updated from a pre-existing DB. Given my well defined problem (this is a fictional example) I talk to the web designer and agree to provide 2 Result Sets, one will be a 1 dimensional array containing all of the States that they serve (eg, AK, AL, AR, etc), and the other will be a 2 dimensional array(table, list, whatever) containing all of the Cities and States that they serve (eg, Chicago, IL; Birmingham, AL; etc). I also agree to provide this Alphabetized by State and then City.

    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.
    Thank God I'm not too early!

  23. #48
    "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)
    Sounds good.

    All of the stuff in my templates are done after all of the other stuff has been finished:

    PHP Code:
    $query db_query("select * from post....");
    while (
    $post db_fetch_array($query))
    {
       
    // DO STUFF WITH RESULTS HERE....

       // Evaluate template 'thread_post' as PHP code, check
       // if $posts exists, and if it doesn't create an empty
       // string, and add the eval'ed PHP to the end of the
       // string.
       
    eval(store_template('thread_post''$posts'1));
    }
    // Build page navigation here...
    // CALCULATE PAGE NAV STUFF...
    // Stores final page nav stuff into $pagenav variable.
    eval(store_template............);

    // Do final output of template.
    eval(get_template('thread_index')); 
    That's not direct out of the code i write, but it's similar.
    Last edited by cyborg from dh; Feb 19, 2003 at 16:44.
    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.

  24. #49
    killall -9 lusers
    Join Date
    Oct 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Port of ZPT to PHP

    Have any of you ever played around with recent versions of Zope? If so you may have had some experience with Zope Page Templates (ZPT). I think this is a phenominal system for templating and does a great job of encouraging the separation of data manipulation from data presentation.

    My company loves the system so much, that we are actually working on a PHP port for our CMS that is in development. I would also like to see the language(s) for ZPT become an adopted standard across other programming languages because the system is generic enough to make that possible.

    The ZPT system consists of three "languages"; TAL (Template Attribute Language) and METAL (Macro Expansion Template Attribute Language) are implimented as XML (and HTML/XHTML) tag attributes, and TALES (Template Attribute Language Expression Syntax) is implimented as the values of TAL and METAL attributes. Both TAL and METAL use their own XML namespaces, so the attributes are perfectly valid in both XML and HTML documents (although I'm not sure what the validators would say about the extra attributes--not to worry as they don't show up in the code that is ultimately sent to the browser). An axample of two template files--one that sets up a main page layout, and another that uses that layout and fills it with other data--follows:
    Code:
    ##File LayoutMaster.html##
    
    <?xml version="1.0" encoding="ISO8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:tal="http://xml.zope.org/namespaces/tal"
        xmlns:metal="http://xml.zope.org/namespaces/metal"
        xml:lang="en" >
    <head metal:define-macro="html_head">
        <title metal:define-slot="html_head_title">This would be the page title</title>
        <link rel="stylesheet" href="/mystyle.css" type="text/css" />
    </head>
    <body metal:define-macro="html_body">
    <!-- put some layout code here -->
    <div metal:define-slot="html_body_maincontent" tal:omit-tag="">
        <p>This is where the main content of the page will go.
        This text is simply dummy text that will be automaticly
        replaced when the template is used (as long as the
        calling template fills this slot). The advantage here
        is that the template designer can see exactly what the
        page is going to look like. A PHP echo statement would
        not show up correctly in a WYSIWYG environment. Other
        simple "template language variables show up, but you
        don't get a good idea of what the page will look like
        with actual content.<p>
    
        <table id="navbarRelated" metal:define-macro="html_body_maincontent_navbarRelated">
            <tr>
                <td tal:repeat="link RelatedLinks" tal:content="structure link/getHTML"><a href="http://example.com">Link Text</a></td>
                <td tal:condition="nothing"><a href="http://example.com">Link Text</a></td>
                <td tal:condition="nothing"><a href="http://example.com">Link Text</a></td>
            </tr>
        </table>
    </div>
    <!-- put some layout code here -->
    </body>
    </html>
    Code:
    ##File pagetemplate.html##
    
    <?xml version="1.0" encoding="ISO8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:tal="http://xml.zope.org/namespaces/tal"
        xmlns:metal="http://xml.zope.org/namespaces/metal"
        xml:lang="en" >
    <head metal:use-macro="LayoutMaster.html/html_head">
        <title metal:fill-slot="html_head_title">Home Page</title>
        <link rel="stylesheet" href="/mystyle.css" type="text/css" />
    </head>
    <body metal:use-macro="LayoutMaster.html/html_body">
    <!-- put some layout code here -->
    <div metal:fill-slot="html_body_maincontent">
        <p>This is the actual content of the page.<p>
    
        <table id="navbarRelated" metal:use-macro="LayoutMaster.html/html_body_maincontent_navbarRelated">
            <tr>
                <td tal:repeat="link RelatedLinks" tal:content="structure link/getHTML"><a href="http://example.com">Link Text</a></td>
                <td tal:condition="nothing"><a href="http://example.com">Link Text</a></td>
                <td tal:condition="nothing"><a href="http://example.com">Link Text</a></td>
            </tr>
        </table>
    </div>
    <!-- put some layout code here -->
    </body>
    </html>
    The final output might look something like:
    Code:
    <?xml version="1.0" encoding="ISO8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
        xml:lang="en" >
    <head>
        <title>Home Page</title>
        <link rel="stylesheet" href="/mystyle.css" type="text/css" />
    </head>
    <body>
    <!-- put some layout code here -->
        <p>This is the actual content of the page.<p>
        <table id="navbarRelated">
            <tr>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
                <td><a href="http://example.com">Link Text</a></td>
            </tr>
        </table>
    <!-- put some layout code here -->
    </body>
    </html>
    The fact that pagetemplate.html file contains much of the exact same code as LayoutMaster.html may seem redundant at first. However, this is because in both Zope and the PHP CMS we are working on, the template files are not simply edited directly on the filesystem. Instead, the file would be downloaded through the CMS, edited, and uploaded through the CMS; or the file could be edited in an online text box or WYSIWYG control. The redundancy is due to macro-expansion during editing. By expanding the macros during editing (but retaining the "metal:use-macro" attributes) someone can edit a template that only defines the "main content" of a page, but that template will still include the layout code of the master template(s). However, if the user changes any of this macro-expanded code in the template they are editing, those changes will not be saved once the template is uploaded. Only the changes to the non-macro code and to the fill-slot code will be saved to the application.

    For more reading on the TAL, METAL, and TALES specifications, please see:
    Last edited by KillAllDash9; Feb 20, 2003 at 08:27.

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

    struts

    If we are going to bring other languages into the picture...

    I can't believe that no where in this PHP forum, while discussing the seperation of business logic from presentation logic, that not a single post has mentioned the Struts framework. It wasn't until about a week ago that I discovered the true purpose (and beauty) of Struts after reading the most recent Linux Magazine entitled "The Java Issue."

    Let me just throw this out there, Struts is absolutely amazing. I personally believe that it is the solution to the problem that web developers have faced for the last several years, which is being able to design a web project which is maintainable, reuseable and flexible.

    While I am in no way associated with the book or its publishers (hence this is not a plug) I recommend that every serious web developer should buy (or take a long coffee break at Borders/Barnes & Nobel to read) the book Struts KickStart. I say this for several reasons. First, it covers the basics of the Model 2 implementation of MVC which Struts implements. Second, it covers the wireframing and planning of an OOP web application (regardless of language). Finally, it has a very large section on the JSTL tag libraries, certainly an elegant solution to "templates" and the seperation of business and presentation logic (hence the relation to this thread).

    While you don't need to go out and download Tomcat and use Struts, you can use just about every tecnique in the book when developing your PHP application. I am currently working to build off of phrame to make a Struts-like framework for PHP (I will either work with or build on what the phrame developers have contributed. While it was a good start, it is far from complete). I believe that if we work together we can stop this fury of CMS releases and actually build something which we can all use when developing our own projects.

    <opinion level="offensive">All this talk about .NET around here, I had to throw in the giants who started the idea in the first place, since it is clear that M$ just ripped off the jakarta project.</opinion>


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
  •