Abstract class oddity..
Posted: Thu Jul 27, 2006 4:22 pm
Am I doing something wrong?
The abstract class:
The child:
The script:
The output:
er?!
EDIT: corrected a syntax error, but still the same output.
The abstract class:
Code: Select all
<?php
abstract class AbstractView
{
protected $template;
protected $smarty;
protected $model;
protected function __construct (Smarty $smarty, iModel $model)
{
$this->smarty = $smarty;
$this->model = $model;
$this->smarty->caching = false;
$this->smarty->config_dir = realpath('includes/config');
$this->smarty->compile_dir = realpath('includes/templates_c');
$this->smarty->template_dir = realpath('includes/templates');
}
public function setTemplate ($template)
{
if ($this->smarty->template_exists($template)) {
$this->template = $template;
} else {
throw new FileNotFoundException ('Template file not found: ' . $template);
}
}
public function assignVariable ($var, $val)
{
$this->smarty->assign($var, $val);
}
public function displayPage ()
{
if (!is_null($this->template)) {
$this->smarty->display($this->template);
}
}
}
?>Code: Select all
<?php
class jmt_IndexView extends AbstractView implements iView
{
public function __construct (Smarty $smarty, iModel $model)
{
parent::__construct($smarty, $model);
$this->setTemplate('index.tpl');
$this->getNews();
$this->getUserData();
}
protected function getNews ()
{
$this->assignVariable('news', $this->model->getNews());
}
protected function getUserData ()
{
foreach ($this->model->getUserData() as $var => $val) {
$this->assignVariable($var, $val);
}
}
}
?>Code: Select all
<?php
try {
$db = new jmt_Database( $CONFIG['DB']['HOST'],
$CONFIG['DB']['USER'],
$CONFIG['DB']['PASS'],
$CONFIG['DB']['DATABASE']
);
} catch (Exception $e) {
var_dump($e);
}
if ((!empty($_COOKIE['stkUserId'])) && (!empty($_COOKIE['stkPass']))) {
try {
$user = new jmt_User($db);
$user->loginWithId($_COOKIE['stkUserId'], $_COOKIE['stkPass']);
$model = new jmt_IndexModel($db, $user);
} catch (Exception $e) {
var_dump($e);
}
} else {
try {
$model = new jmt_IndexModel($db);
} catch (Exception $e) {
var_dump($e);
}
}
$view = new jmt_IndexView(new Smarty(), $model);
var_dump($view);
//$view->displayPage();
?>Code: Select all
object(jmt_IndexView)#4 (0) { }EDIT: corrected a syntax error, but still the same output.