That is really your main or outer View but could also be considered you Response. I might suggest adding a setContent($content) method to it and registering it with the Locator. Then the your Actions composite rather than inherit, and just set the content are return. Note - It becomes a Response class if you also add redirect and headers to it.Hurreman wrote:All my actions inherit from a base class with the basic layout.
You Home class is pretty simple, but I might split up The News class:
Code: Select all
<?php
class NewsModel
{
private $db;
private $user;
public function __construct(&$locator)
{
$this->db = $locator->get('MySQL');
$this->user = $locator->get('User');
}
public function getNews()
{
$stmt = $this->db->createQuery('SELECT * FROM news ORDER BY newsDate DESC, newsID DESC');
$rs = $stmt->execute();
$allrows = $rs->getAllRows(); // or whatever code you need here
return $allrows;
}
public function getUserName($author)
{
return $this->user->getUserName($author);
}
}
class NewsView
{
private $db;
private $user;
public function __construct(&$locator)
{
$this->model = new NewsModel($locator);
}
public function printNews()
{
$rs = $this->model->getAllRows();
foreach ($rs as $row)
{
echo '<div id="newscontent">';
echo '<p class="newsTitle">' . stripslashes( $row['newsTitle']) . '</p>';
if($row['newsImage'])
{
echo '<img class="newsimage" src="images/pageimages/' . $row['newsImage'] . '"/>';
}
$body = stripslashes($row['newsText']);
$bodyArr = explode(chr(13),$body);
foreach($bodyArr as $content)
{
if(trim($content=='') || !isset($content))
{
echo '<br/>';
}
else
{
echo '<p class="newsText">' . $this->getPreparedString($content) . '</p>';
}
}
echo '<p class="newsAuthor">Written by <i>' . $this->model->getUserName($row['newsAuthor']) . '</i></p>';
echo '</div>';
}
}
public function getPreparedString($str)
{
$str = strip_tags($str);
$str = str_replace('[b]','<b>',$str);
$str = str_replace('[/b]','</b>',$str);
$str = str_replace('[i]','<i>',$str);
$str = str_replace('[/i]','</i>',$str);
$str = str_replace('[u]','<u>',$str);
$str = str_replace('[/u]','</u>',$str);
$str = str_replace('[list]','<ul>',$str);
$str = str_replace('[/list]','</ul>',$str);
$str = str_replace('[item]','<li>',$str);
$str = str_replace('[/item]','</li>',$str);
$str = preg_replace("!\\[url=(.*?)\\](.*?)\\[/url\\]!i", "<a target="_blank" href="\\1">\\2</a>", $str);
return $str;
}
}
?>