SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 53 of 53
  1. #51
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by auricle
    Hmm... I don't know what you mean by 'batch job' in this context, but...
    Just that it receives no input once it has started.

    Quote Originally Posted by auricle
    Is there necessarily anything wrong with having one view per page?
    Nothing. It was just the duplication and there are alternatives. I think the view and controller are not so separated in web development when both have to be created afresh at every page request.

    For example, the template could drive the whole show by including the controller specific information as a template language extension. This way you only need one controller that does nothing except "run" the template.

    Another possiblity is creating the page from small templated elements. Here all the page specific stuff is in the controller as it is from this that the list of sub-elements comes. The view parts would map more closely to the domain obects than the page structure of the site.

    You can even dispense with both view and controller and just place controller code (e.g. access rights) straight into the domain objects. A group of generic controller/views paints them all. Only really useful for admin. interfaces as there is little control over the look and feel. This is far too limiting for websites.

    All of these approaches have limitations (I don't have an answer). I am getting motivated to explore alternatives though.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  2. #52
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    single html file and separate views into blocks
    This is where you have the Pattern Template Method no ? This would be the ideal solution as I see it

    Quote from one source...

    The general approach of the Template Method is to define a set of general class methods which sub classes can (perhaps optionally) override the template method with a different implementation. This then allows either the superclass or some other class to be given any object containing the template method(s) and execute it, producing varying output
    Ie One kind of Template Method may be the HEAD of the document with a default TITLE, whereby later you can give another HEAD which has a more suitable TITLE yes ?

    Unfortunately the link I had at WACT is down for this Pattern

    There was an example on this site for this very Pattern...

    --EDIT--

    Found the example script...

    PHP Code:
    <?php
    // super class
    class Page {
        
    // Template method
        
    function header() {
            
    $html = <<<EOD
    <html>
    <head>
    <title>TemplateMethod.com</title>
    </head>
    EOD;
            return 
    $html;
        }
        
    // Template method
        
    function footer() {
            
    $html = <<<EOD
    <p>&copy; TemplateMethod Inc. 2003</p>
    </body>
    </html>
    EOD;
            return 
    $html;
        }
        
    // Template method
        
    function body() {
            
    // Do nothing
        
    }
    }

    class 
    Login extends Page {
        
    // Template method
        
    function body() {
            
    $html = <<<EOD
    <form action="login.php" method="post">
    <input type="text" name="username"><br>
    <input type="password" name="password"><br>
    <input type="submit" name="login" value="login">
    </form>
    EOD;
            return 
    $html;
        }
    }

    class 
    News extends Page {
        
    // Template method
        
    function header() {
            
    $html = <<<EOD
    <html>
    <head>
    <title>TemplateMethod.com - Latest News</title>
    </head>
    <body>
    EOD;
            return 
    $html;
        }
        
        
    // Template method
        
    function body() {
            
    $html = <<<EOD
    <h1>Latest News</h1>
    <!-- Display database query results here perhaps -->
    EOD;
            return 
    $html;
        }
    }

    class 
    PageWriter {
        var 
    $page;
        function 
    PageWriter($page) {
            
    $this->page $page;
        }
        function 
    render() {
            
    $html $this->page->header();
            
    $html .= $this->page->body();
            
    $html .= $this->page->footer();
            return 
    $html;
        }
    }

    switch ( 
    strtolower(@$_GET['page']) ) {
        case 
    'login':
            
    $page = new Login();
        break;
        case 
    'news':
            
    $page = new News();
        break;
        default:
            
    trigger_error('Invalid page',E_USER_ERROR);
        break;
    }

    $pageWriter = new PageWriter($page);
    echo ( 
    $pageWriter->render() );
    ?>
    Enjoy
    Last edited by Dr Livingston; Oct 27, 2003 at 13:23.

  3. #53
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Just that it receives no input once it has started.
    The term 'batch' makes me think of the same operation being performed on a number of different entities (or files). For example, I might find that a number of audio files I'm working on (I'm an audio engineer) required the same amount of mastering compression, so I process them one after the after without changing any settings. I can't quite see the analogy in relation to a web app unless you mean that, because several requests might share a view, the same process is enacted when any one of them is instantiated. Anyway, I digress slightly.
    Quote Originally Posted by Dr Livingston
    This is where you have the Pattern Template Method no ?
    Yes, although I have to admit that I'm with Selkirk here. I like the idea of a template class which uses placeholders, e.g. {PLACEHOLDER} and separates blocks with comments, e.g. <!-- BEGIN BLOCK: block -->, <!-- END BLOCK: block -->. (I wouldn't go as far as Smarty with conditionals, though). Anyway, you're right to the extent that a particular block is loaded into the final output depending on which view was selected. Your separating the different blocks into different classes means that only the html that is used is loaded. Which gets back to my original point about only loading php code which will be used.


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
  •