2017-03-14

Mar 15 In-Class Exercise.

Post your solutions to the Mar 15 In-class Exercise here.
Best, Chris Pollett
(Edited: 2017-03-15)
Post your solutions to the Mar 15 In-class Exercise here. Best, Chris Pollett
2017-03-15

-- Mar 15 In-Class Exercise
David Lerner


(Edited: 2017-03-15)
David Lerner ---- <nowiki> <?php //index.php require_once "LetsBuildView.php"; require_once "WebLayout.php"; $data['title'] = "Let's Build Something"; $data['content'] = " Yippee! It works! "; $data['content'] .= " A controller contains only the logic of the application so it does not output html. It would kind of be equivalent to the view classes here, except there is no logic to handle here. "; $view = new LetsBuildView("WebLayout"); $view->display($data); ?> </nowiki> ---- <nowiki> <?php //LetsBuildView.php require_once "View.php"; class LetsBuildView extends View { public function render($data = []) { ?> <h1><?=$data['title']?></h1> <p><?=$data['content']?></p> <?php } } ?> </nowiki> ---- <nowiki> <?php //WebLayout.php require_once "Layout.php"; class WebLayout extends Layout { public function renderHeader($data) { ?><!DOCTYPE html> <html> <head><title><?=$data['title']?></title></head> <body> <?php } public function renderFooter($data) { ?> </body> </html><?php } } ?> </nowiki>

-- Mar 15 In-Class Exercise
Rohan Kumar
<?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
    }
}
To get a controller to work with a view, attach a view to a controller. When the controller detect changes, the controller will notify the view to re-render.
Rohan Kumar <pre> <?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 } } </pre> <pre> <?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 } } </pre> To get a controller to work with a view, attach a view to a controller. When the controller detect changes, the controller will notify the view to re-render.

-- Mar 15 In-Class Exercise
<?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>";     } }   
<pre> <?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>"; } } </pre>

-- Mar 15 In-Class Exercise
Name: Pei Lian Liu
 <?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);
(Edited: 2017-03-15)
'''Name: Pei Lian Liu''' <?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);

-- Mar 15 In-Class Exercise
Name: Yash Parikh
<?php /**
 * Created by PhpStorm.
 * User: yashparikh
 * Date: 3/15/17
 * Time: 2:05 PM
 */
require_once "Layout.php";
class WebLayout extends Layout {
    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
    }
} ?>
<?php /**
 * Created by PhpStorm.
 * User: yashparikh
 * Date: 3/15/17
 * Time: 2:05 PM
 */
require_once "View.php";
class LetsBuildView extends View {
    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
    }
}
Name: Yash Parikh <?php /** * Created by PhpStorm. * User: yashparikh * Date: 3/15/17 * Time: 2:05 PM */ require_once "Layout.php"; class WebLayout extends Layout { 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 } } ?> <?php /** * Created by PhpStorm. * User: yashparikh * Date: 3/15/17 * Time: 2:05 PM */ require_once "View.php"; class LetsBuildView extends View { 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 } }

-- Mar 15 In-Class Exercise
Kirtan Patel <?php
require_once "View.php";
class LetsBuildView extends View {
    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
    }
}
<?php
require_once "Layout.php";
class WebLayout extends Layout {
    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
    }
} ?>
Kirtan Patel <?php require_once "View.php"; class LetsBuildView extends View { 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 } } <?php require_once "Layout.php"; class WebLayout extends Layout { 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 } } ?>

-- Mar 15 In-Class Exercise
Name: Mohnish Kadakia <?php
require_once "View.php";
class LetsBuildView extends View {
    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
    }
}
<?php require_once "Layout.php";
class WebLayout extends Layout {
    function renderHeader($data) {
        $title = (isset($data['title'])? $data['title']: "Title");
        ?>
        <html>
        <head>
            <title><?php echo $title ?></title>
        </head>
        <?php
    }
    function renderFooter($data) {
       ?>
        </html>
        <?php
    }
} ?>
(Edited: 2017-03-15)
Name: Mohnish Kadakia <?php require_once "View.php"; class LetsBuildView extends View { 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 } } <?php require_once "Layout.php"; class WebLayout extends Layout { function renderHeader($data) { $title = (isset($data['title'])? $data['title']: "Title"); ?> <html> <head> <title><?php echo $title ?></title> </head> <?php } function renderFooter($data) { ?> </html> <?php } } ?>

-- Mar 15 In-Class Exercise
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)
<pre> '''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 } } </pre>

-- Mar 15 In-Class Exercise
<?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)
<pre> <?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 } } ?> </pre>
[ Next ]
X