Results 1 to 15 of 15
  1. #1
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101

    [PHP] Tagless web pages

    Currently I am using HMTL/XHTML tags and PHP code mixed in my pages, e.g.
    PHP Code:
    <img src="<?php echo $imagename ?>" />
    Most of the times pages get pretty ugly no matter how neatly I try to code.

    Recently I am thinking converting to (X)HTML generation with PHP. Means, I will build a small library for the HTML tags, and create the whole HTML without coding a single tag. Example:
    PHP Code:
    $image = new imgTag();
    $image->src "/aaaa/sss/cc.gif";
    $image->width
    $image
    ->height
    $image
    ->alt
    ... 
    etc. You get the idea.
    I heard there are quite a few people practicing this, but I want to know how this style effect the speed/performance of the website.

    Any experiences? Insights?
    Closed for winter...

  2. #2
    Join Date
    Sep 2004
    Location
    Beaverton, OR
    Posts
    261
    Interesting concept. I can't really think of any examples that I've seen along these lines. Seems like positioning the elements would really complicate a model like this.

    Personally, I would look at adopting a framework that cleanly seperates the presentation from the data (such as a MVC design pattern). At a minimum a template based system..

    If you have any good examples of websites built in this fashion I would be interested in checking it out.

    As far as performance goes I have to imagine it would suffer a little bit. My basis for this is the fact that I suspect you'll be creating, assigning and manipulating far more objects to render a page then when you use the traditional model. Whether or not the difference is actually noticable is hard to say.

    Regards,
    Jerret

  3. #3
    Join Date
    Mar 2009
    Posts
    2,218
    Have you considered template engines, such as Smarty?

    http://www.smarty.net/

    The idea is you separate the data manipulation code (PHP) from the presentation code (HTML).

  4. #4
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101
    Yes, actually I looked at it few weeks ago.
    Nice concept, but still not completely separates the HTML and the language. You still have to insert Smarty tags into templates.
    Cleaner for sure, but not what I am asking.

    I am talking about complete creation of the HTML code in PHP. From the <!DOCTYPE>, to the </html>. Including function calls to JavaScript functions(onmouseover, onclick etc.) and inline style elements.
    Closed for winter...

  5. #5
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    It could definably be done, and could be useful to some one that thinks like that. If you're thinking about implementing this.. you're probably that type of mind.

    When ever I do any (x)html generation in Perl this is the technique I use.

    In PHP you could possibility just re-purpose the DomDocument Class and save your self a lot of work. That is, as long as you're wanting to output valid XHTML.

  6. #6
    Join Date
    Mar 2009
    Location
    Gods Own Country
    Posts
    681
    Concept seems pretty nice.. but why write 4 lines of HTML code when it can be done in just one line? Till now, I have seen only html forms with OOP concept applied. Zend, CakePHP etc use this. Really, should all html tags be Object Oriented?
    Fabin Mundattil @ Xieles Support
    High Quality Server Management | support @ xieles.com
    http://xieles.com

  7. #7
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101
    That is the concept. I am not questioning if should all tags be OOP.
    I am after an extremely clean code. Every page will have only one <?php and one ?>. Everything will be done with 100% PHP objects.

    If I also can create the CSS library, this will give me the flexibility of creating the style on the fly. Which means I don't have to create multiple CSS files for different browsers, platforms, languages etc. The very same page can render itself for IE6, Firefox, iPhone, Blackberry, X brand cellphone or some hand-held device.
    Closed for winter...

  8. #8
    Join Date
    May 2009
    Posts
    766
    All depends on your application. I've written function libraries that resemble Perl's CGI.pm (qw/tandard/) to handle some of this kind of stuff:

    PHP Code:
    echo
      
    p
     
    (
      
    b("Warning!", array("style" => "color:red") . 
      
    " This page was made using HTML functions!",
      array(
    "class" => "alert")
     ); 
    I can see a lot of validity in an OOP approach as well. It all comes down to the amount of overhead you are willing to introduce vs. the readability improvement--and inherent increase in development rapidity.

    If you are working on a site that uses a standard template, I might opt for something like this:

    PHP Code:
    include("template_header.html");

    // my functionalized dynamic HTML

    include("template_footer.html"); 
    I don't see the point in using a OOP DOM framework to keep rebuilding the same bits of HTML on every page.

    I'd be interested to know what you end up implementing. Also, I'm not any kind of expert on the DOM functionality that PHP has, but it seems that there may be some solutions you can already incorporate...maybe someone out there with better familiarity can shed some light.

  9. #9
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    I thought the concept of building around DOMDocument was pretty good so I've created a little View class for my self.

    I've attached my prototype. You've got to be careful and make sure you specify a valid DTD. Other wise getElementByID doesn't work.
    Attached Files Attached Files

  10. #10
    Join Date
    Nov 2006
    Location
    Karachi, Pakistan
    Posts
    1,349
    I think its a terrible idea. By making templates entirely PHP your making it impossible for a HTML developer to modify your designs. Use smarty or html with php . Just PHP is a really bad idea.

  11. #11
    Join Date
    May 2009
    Posts
    766
    I assume your talking to the original poster, not the most recent one...since his third link is the HTML template...(quoting helps when you're going back more than one post )

    Frankly I don't see the big deal. Not every project is going to have HTML designers working on it. I still contend however that it's needless to dynamically generate your templates in terms of CPU cycles. For a nice cross-breed between the two, check out phpBB's template caching routines.

  12. #12
    Join Date
    Nov 2006
    Location
    Karachi, Pakistan
    Posts
    1,349
    Quote Originally Posted by mattle View Post
    I assume your talking to the original poster, not the most recent one...since his third link is the HTML template...(quoting helps when you're going back more than one post )

    Frankly I don't see the big deal. Not every project is going to have HTML designers working on it. I still contend however that it's needless to dynamically generate your templates in terms of CPU cycles. For a nice cross-breed between the two, check out phpBB's template caching routines.
    Yeah I was talking about the OP

    Xeentech's code is a lot of fun for the PHP programmer but I don't think its practical. Any widely used script is going to encounter HTML templates that don't validate. Xeentech's code requires validation so it won't do. It also is slower because of the DOM parsing. Still very interesting concept no doubt.

    phpBB uses smarty caching right? Personally I think straight php echos in a mostly html template is best.

  13. #13
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    Quote Originally Posted by Website themes View Post
    Yeah I was talking about the OP

    Xeentech's code is a lot of fun for the PHP programmer but I don't think its practical. Any widely used script is going to encounter HTML templates that don't validate. Xeentech's code requires validation so it won't do. It also is slower because of the DOM parsing. Still very interesting concept no doubt.

    phpBB uses smarty caching right? Personally I think straight php echos in a mostly html template is best.
    The validity of the template is really not going to be an issue if I ever do use this concept.. I don't intent on working with people incapable of writing valid xml.

    As for DOM parsing, if I ever did use this there would be a robust caching mechanism in place. Smarty has to parse it's template.. and you don't seem to think that's a problem.

    And as for PHP echo()S being the solution. You're insane. That's neither fun for the PHP developer, and certainly not an (x)HTML designer.

    I really like the concept of template inheritance. If that could be worked into this model I'd implement this seriously.

  14. #14
    Join Date
    Nov 2006
    Location
    Karachi, Pakistan
    Posts
    1,349
    Quote Originally Posted by Xeentech View Post
    The validity of the template is really not going to be an issue if I ever do use this concept.. I don't intent on working with people incapable of writing valid xml.

    As for DOM parsing, if I ever did use this there would be a robust caching mechanism in place. Smarty has to parse it's template.. and you don't seem to think that's a problem.
    Smarty has caching. It parses the template just once and generates a .php file. Then at every request it compares the file modification time stamp and if the original template has not been modified it just includes the .php file.

  15. #15
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    Quote Originally Posted by Website themes View Post
    Smarty has caching. It parses the template just once and generates a .php file. Then at every request it compares the file modification time stamp and if the original template has not been modified it just includes the .php file.
    That was kind of my point... As I said, if I was going to use this seriously "there would be a robust caching mechanism in place."

Similar Threads

  1. any ideas why non-ssl pages are blank, ssl pages work
    By AtoZ in forum Hosting Security and Technology
    Replies: 3
    Last Post: 02-01-2008, 11:49 PM
  2. Sitewide Link 4 Sale -15000 pages indexed many PR Pages
    By mddv in forum Advertising Offers
    Replies: 0
    Last Post: 09-12-2005, 07:57 AM
  3. Text Links available on several pr4 pages and thousands of pr2 pages
    By brycewilson in forum Other Offers & Requests
    Replies: 0
    Last Post: 03-21-2005, 05:59 AM
  4. Link on 10 pages PR 4(3 pages) 3(7) 3 months, for hosting
    By designcodes in forum Other Offers & Requests
    Replies: 18
    Last Post: 06-02-2004, 12:59 AM
  5. Replies: 6
    Last Post: 05-01-2004, 09:39 AM

Posting Permissions

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