MVC - xsl/xml as model/view ?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Hurreman
Forum Commoner
Posts: 61
Joined: Sat Apr 29, 2006 8:42 am

MVC - xsl/xml as model/view ?

Post by Hurreman »

Lately, I've been planning a larger project and trying to figure out how everything should work before I actually start coding.
My last try on MVC and separating presentation from logic wasn't very successful (due to lack of planning beforehand),.

What I've got so far is a modified version of arborint's frontcontroller and servicelocator skeleton, which works perfectly. My problem has been in the model/view, where I end up having a lot of mixed php/xhtml output. I've got PHP code generating xhtml, and well, it's far from a pretty solution. I've been looking at a couple of solutions (using Template Lite or a similiar template engine), but lately I've been curious about using xml/xsl. Would it be a bad idea using xml/xsl as view/model?

Also, the project will rely on a lot of DOM/Ajax drag-drop, and I'm not sure how using xml/xsl would affect working with the DOM with javascript...



I'll paste some of my current and horrible, HORRIBLE code for everyone to laugh at... :oops:


Action/Viewboards.php

Code: Select all

<?php
include_once('inc/forumlayout.php');

class viewboards extends forumlayout
{
    function printContent()
    {
        echo '<div id="content">';
        $this->forum->printBoards();
        echo '</div>';
    }

    function execute()
    {
        $this->printHead();
        $this->printHeader();
        $this->printNavigation();
        $this->printContent();
        $this->printRightDiv();
        $this->printFooter();
    }
}
?>
Function from within Lib/Forum.php

Code: Select all

// Pre: Table 'boards' must exist and have entries
    // Post:
    // Note: Prints a table of the boards found in the 'boards' table.
    function printBoards()
    {
        $query = "SELECT * FROM boardcategories";
       
        $stmt = $this->db->createQuery($query);
        $rs = $stmt->execute();
        echo '<table cellspacing="0" cellpadding="0" class="boards">' . "\n";


        // Print all categories and their child-boards
        while($rs->next())
        {
            echo '<tr>' . "\n";
            echo '<td class="topBoardTitle">' . $rs->getField('boardCatTitle') . '</td>';
            echo '<td class="topBoardTopics">Topics</td>';
            echo '<td class="topBoardPosts">Posts</td>';
            echo '<td class="topBoardLastPost">Last Post</td>';
            echo '</tr>';


            // Select all child boards
            $stmt2 = $this->db->createQuery('SELECT * FROM boards WHERE boardCatID=? ORDER BY boardOrder,boardID');
            $stmt2->setParameter(1,$rs->getField('boardCatID'));
            $rs2 = $stmt2->execute();
            while($rs2->next())
            {
                echo '<tr>';
                echo '<td class="boardTitle">';
                echo '<p><a href="forum.php?action=listposts&id=' . $rs2->getField('boardID') . '">' . $rs2->getField('boardTitle') . '</a></p><p>' . $rs2->getField('boardDesc') . '</p></td>';
                echo '<td class="boardTopics">' . $this->getBoardTopics($rs2->getField('boardID')) . '</td>';
                echo '<td class="boardPosts">' . $this->getBoardPosts($rs2->getField('boardID')) . '</td>';
                echo '<td class="boardLastPost">';
                $this->printBoardLastPost($rs2->getField('boardID'));
                echo '</td>';
                echo '</tr>';
            }
        }
        echo '</table>';
    }
Post Reply