Hey folks what i am trying to do today since i have my controller action class sorted(thanks for the help getting started there guys). I am now working on a templater more specifically the template class works in for the basic bit but i want to make it put the view template into the layout template.
template.php
indexcontroller.php
/view/index/index.php
/layout/layout.php
So far my best effort outputs
template.php
PHP:
Class CabbitTemplate
{
private $CabbitRegistry;
private $vars = array();
function __construct($CabbitRegistry)
{
$this->CabbitRegistry = $CabbitRegistry;
}
public function __set($index, $value)
{
$this->vars[$index] = $value;
}
public function layout()
{
$viewPath = __SITE_PATH . '/application/layout' . '/layout.php';
if (file_exists($viewPath) == false)
{
throw new Exception('Template not found in '. $viewPath);
return false;
}
return $viewPath;
}
function show($name)
{
$viewPath = __SITE_PATH . '/application/views' . '/' . $name . '.php';
if (file_exists($viewPath) == false)
{
throw new Exception('Template not found in '. $viewPath);
return false;
}
// Load variables
foreach ($this->vars as $key => $value)
{
$$key = $value;
}
include $this->layout($viewPath);
}
}
PHP:
class inderController Extends CabbitControllerAction
{
$this->CabbitRegistry->CabbitTemplate->show('/index/index');
}
/view/index/index.php
PHP:
<h1><?php echo $welcome; ?></h1>
<p><?php echo $status; ?></p>
<?php echo $user; ?>
<br />
<a href='/user/logout'>Logout</a>
/layout/layout.php
PHP:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<div id="content">
<?php echo $this->CabbitRegistry->CabbitTemplate->layout(); ?>
</div>
</body>
</html>
So far my best effort outputs
HTML:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<div id="content">
/Users/jerryroy/Sites/Cabbit 1.0/application/layout/layout.php</div>
</body>
</html>