<?php
//WebLayout.php
require_once 'Layout.php';
class WebLayout extends Layout
{
public function renderHeader($data)
{
?>
<!DOCTYPE html>
<html>
<head>
<title>
<?= isset($data['title']) ? $data['title'] : ?>
</title>
</head>
<body>
<?php
}
public function renderFooter($data)
{
?>
</body>
</html>
<?php
}
}
<?php
//LetsBuildView.php
require_once 'View.php';
class LetsBuildView extends View
{
public function render($data = [])
{
?>
<h1>
<?= isset($data['title']) ? $data['title'] : ?>
</h1>
<p>
<?= isset($data['content']) ? $data['content'] : '' ?>
</p>
<?php
}
}
<?php
class LetsBuildView extends View
{
public function render($data = []){
return $data["content"];
}
}
class Layout extends Layout
{
public $view;
public function __construct(View $view)
//notice type hinting allowed for objects
{
$this->view = $view;
}
public function renderHeader($data){
return "<html><head><title>" . $data["title"] . "</title></head><body>";
}
public abstract function renderFooter($data){
return "<footer>" . "This is the footer" . "</footer></body></html>";
}
}
<?php //index.php require_once "LetsBuildView.php"; require_once "WebLayout.php";
class LetsBuildView extends View {
public function render($data = []) {
echo '<body>
<h1>'.$data['title'].'</h1>
'.$data['content'].'
</body>';
}
}
class WebLayout extends Layout {
public function renderHeader($data) {
echo '<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title>'.$data['title'].'</title>
</head>';
}
public function renderFooter($data) {
echo '</html>';
}
}
$data['title'] = "Let's Build Something";
$data['content'] = "<p>Yippee! It works!</p>";
$data['content'] .= "<p>I have figured out how to get this to work with controllers</p>";
$view = new LetsBuildView("WebLayout");
$view->display($data);
* Created by PhpStorm. * User: yashparikh * Date: 3/15/17 * Time: 2:05 PM */
function renderHeader($data) {
$title = (isset($data['title'])? $data['title']: "Title");
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title ?></title>
</head>
<body>
<?php
}
function renderFooter($data) {
?>
</body>
</html>
<?php
}
} ?>
* Created by PhpStorm. * User: yashparikh * Date: 3/15/17 * Time: 2:05 PM */
public function render($data = [])
{
// TODO: Implement render() method;
$title = (isset($data['title'])? $data['title']: "Title");
$content = (isset($data['content'])? $data['content']: "Content");
?>
<h1><?php echo $title ?></h1>
<p> <?php echo $content ?></p>
<?php
}
}
public function render($data = [])
{
// TODO: Implement render() method;
isset($data['title']) ? $data['title']: "";
isset($data['content']) ? $data['content']: "";
?>
<body>
<h1><?php echo $data['title'] ?></h1>
<p> <?php echo $data['content'] ?></p>
</body>
<?php
}
}
function renderHeader($data) {
isset($data['title'])? $data['title']: "";
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $data['title'] ?></title>
</head>
<?php
}
function renderFooter($data) {
?>
</html>
<?php
}
}
?>
public function render($data = [])
{
$title = (isset($data['title'])? $data['title']: "Title");
$content = (isset($data['content'])? $data['content']: "Content");
?>
<body>
<h1><?php echo $title ?></h1>
<p><?php echo $content ?></p>
</body>
<?php
}
}
function renderHeader($data) {
$title = (isset($data['title'])? $data['title']: "Title");
?>
<html>
<head>
<title><?php echo $title ?></title>
</head>
<?php
}
function renderFooter($data) {
?>
</html>
<?php
}
} ?>
Michael Nguyen
<?php
// LetsBuildView.php
require_once "view.php";
class LetsBuildView extends View
{
public function render($data = []){
?>
<h1><?php
if(!empty($data['title'])){
echo $data['title'];
}?>
</h1>
<p><?php
if(!empty($data['content'])){
echo $data['content'];
}?>
<?php
}
}
<?php
//WebLayout.php
require_once "layout.php";
class WebLayout extends layout
{
public function renderHeader($data){
?>
<!DOCTYPE html>
<head>
<title><?php
if(!empty($data['title'])){
echo $data['title'];
}
?>
</title>
</head>
<body>
<?php
}
public function renderFooter($data){
?>
</p>
</body>
</html>
<?php
}
}
(Edited: 2017-03-15)
<?php
require_once "View.php";
class LetsBuildView extends View
{
public function render($data = [])
{
?>
<body><h1>
<?php echo $data['title'] ?>
</h1></body>
<?php echo $data["content"] ?>
<?php
}
}
?>
<?php
require_once "Layout.php";
class WebLayout extends Layout{
public function renderHeader($data){
?>
<html>
<head>
<title>Yay</title>
</head>
<?php
}
public function renderFooter($data) {
?>
</body>
</html>
<?php
}
}
?>
(Edited: 2017-03-15)