Zend Framework MVC Issues
Posted: Wed Jul 05, 2006 7:53 am
I've been rewriting a medium sized, very procedurial PHP4/MySQL web application in glorious OO PHP 5 Zend Framework and I've been learning a lot in the process. Some of you might think I'm a bit crazy using a technology a new as the ZF in an application that is going to be used in production but I have faith in my abilities as a tester and the fact that I can circumvent/modify the ZF wherever necessary.
Anyway my problem is, I've got a view script that looks like this:
The problem is this isn't nearly structured enough for me. It seems too similar to the logic, markup soup I was using in the previous version of this application. So I've been pondering to myself about how to make this more structured and also how structured should this be?
The best idea I have come up with is to extend Zend_View into a global class called TillingView (Tilling being the prefix for all my classes in this project) and then extend that to TillingViewList for list pages (pages where output is displayed, you can delete rows and there is page spanning functionality) and extend that to TillingViewListSite which would be specific to this particular view script.
The aim of doing all this would be to then have enough methods so that the view script itself would almost have no markup in it at all just calls to helper methods that either format data or output markup structure with subsitutations. This would of course also have the advantage that all the list page I create (of which there are 4, site, report, answer set and question) I have TillingViewList which will be common to them all.
I'm still getting to grips with the idea of MVCs but what do you think of my ideas here?
Anyway my problem is, I've got a view script that looks like this:
Code: Select all
<?php
require 'administrationHeader.php';
?>
<ul class="buttons">
<li><a href="/Site/Create/">New Site…</a></li>
<li><a href="#" onclick="return tfb.confirm()">Delete Selected</a></li>
</ul>
<br style="clear:left" />
<form method="post" action=".">
<?php
if(!is_null($this->deletedRows)) {
echo '<p>';
if($this->deletedRows == 0) {
echo 'No rows deleted';
} else if ($this->deletedRows == 1) {
echo 'A single row was deleted';
} else {
echo $this->_englishNumbers($this->deletedRows) . ' were rows deleted';
}
echo '</p>';
}
if($this->sites->num_rows) {
?>
<table class="lst">
<tr>
<td class="chkbox" style="visibility:hidden"></td>
<th class="v_actions" scope="col" colspan="5">Actions</th>
<th class="v_title" scope="col">Title</th>
<th class="v_client" scope="col">Client</th>
<th class="v_status" scope="col">Online</th>
</tr>
<?php
while($site = $this->sites->fetch_object()) {
$html = $this->_bulkSubEscape(clone $site, $this->detailedLimit);
$html->siteId = (int)$site->siteId;
$html->longHqVideoUrl = $this->_escape($site->hqVideoUrl);
$html->longLqVideoUrl = $this->_escape($site->lqVideoUrl);
$html->isOnlineStr = var_export((bool)$site->isOnline, true);
$html->useQuestionnaire = var_export((bool)$site->isOnline, true);
$html->useVideo = var_export((bool)$site->isOnline, true);
$html->ucFirstIsOnlineStr = ucfirst($html->isOnlineStr);
if (is_null($site->hqVideoUrl)) {
$html->hqVideoUrl = $this->undefinedMessage;
}
if (is_null($site->lqVideoUrl)) {
$html->lqVideoUrl = $this->undefinedMessage;
}
$html->period = $this->_getPeriod($html->wentOnline, $html->wentOffline);
echo <<< END
<tr>
<td class="chkbox">
<input type="checkbox" onclick="tfb.selectRecord(this)" name="chkRecord_{$html->siteId}"
id="chkRecord_{$html->siteId}" value="{$html->siteId}" />
</td>
<td class="v_action" title="Modify Site…">
<a href="/Site/modify/id/{$html->siteId}">
<img src="/gfx/ico16/mod.png" alt="Modify Site…" />
</a>
</td>
<td class="v_action" title="Modify Questions…">
<a href="/Question/list/id/{$html->siteId}">
<img src="/gfx/ico16/modq.png" alt="Modify Questions…" />
</a>
</td>
<td class="v_action" title="Clone">
<a href="/Site/clone/id/{$html->siteId}" onclick="return confirm('Sure?')">
<img src="/gfx/ico16/cln.png" alt="Clone" />
</a>
</td>
<td class="v_action" title="Preview…">
<a href="/Site/preview/id/{$html->siteId}">
<img src="/gfx/ico16/pre.png" alt="Preview…" />
</a>
</td>
END;
if($html->isOnline) {
echo '<td class="v_action" title="View Online…">';
echo '<a href="/Pub/id/' . $html->siteId . '"><img src="gfx/ico16/go.png" alt="Disabled" /></a>';
echo '</td>';
} else echo '<td> </td>';
echo <<< END
<td class="v_title">
<a name="site{$html->siteId}" href="/Site/list/id/{$html->siteId}#site{$html->siteId}">
{$html->title}
</a>
</td>
<td class="v_client">
<a href="/Client/list/id/{$html->clientId}">{$html->clientName}</a>
</td>
<td class="v_status">
<img src="gfx/ico16/{$html->isOnlineStr}.png" alt="{$html->isOnlineStr}" />
</td>
</tr>
END;
}
echo '</table></form><br />';
echo $this->_pageNav($this->page, 'Site');
} else echo '</form><p>No sites in database</p>';
require 'administrationFooter.php';The best idea I have come up with is to extend Zend_View into a global class called TillingView (Tilling being the prefix for all my classes in this project) and then extend that to TillingViewList for list pages (pages where output is displayed, you can delete rows and there is page spanning functionality) and extend that to TillingViewListSite which would be specific to this particular view script.
The aim of doing all this would be to then have enough methods so that the view script itself would almost have no markup in it at all just calls to helper methods that either format data or output markup structure with subsitutations. This would of course also have the advantage that all the list page I create (of which there are 4, site, report, answer set and question) I have TillingViewList which will be common to them all.
I'm still getting to grips with the idea of MVCs but what do you think of my ideas here?