<?php

require_once '../../Wact/Loader.inc.php';
Wact_Loader::setupWact();

class InnerView extends Wact_View_Scoped {

    function paint() {
?>
<TABLE border="1">
    <TR>
        <TD>{$Animal} = <?php echo $this->myScope->model->Animal ?></TD>
        <TD>{$^Animal} = <?php echo $this->parentScope->model->Animal ?></TD>
        <TD>{$#Animal} = <?php echo $this->rootScope->model->Animal ?></TD>
    </TR>
    <TR>
        <TD>{$Food} = <?php echo $this->myScope->model->Food ?></TD>
        <TD>{$^Food} = <?php echo $this->parentScope->model->Food ?></TD>
        <TD>{$#Food} = <?php echo $this->rootScope->model->Food ?></TD>
    </TR>
</TABLE>
<?php
    }
}

class MiddleView extends Wact_View_Scoped {

    function setUp() {
        $this['inner'] = new InnerView();
    }

    function paint() {
?>
<TABLE border="1">
    <TR>
        <TD>{$Animal} = <?php echo $this->myScope->model->Animal ?></TD>
        <TD>{$^Animal} = <?php echo $this->parentScope->model->Animal ?></TD>
        <TD>{$#Animal} = <?php echo $this->rootScope->model->Animal ?></TD>
    </TR>
    <TR>
        <TD>{$Food} = <?php echo $this->myScope->model->Food ?></TD>
        <TD>{$^Food} = <?php echo $this->parentScope->model->Food ?></TD>
        <TD>{$#Food} = <?php echo $this->rootScope->model->Food ?></TD>
    </TR>
</TABLE>
<blockquote> This is inside a Nested Data Space tag
<?php $this->renderChildren(); ?>
</blockquote>
<?php
    }

}

class MyView extends Wact_View_Root {

    function setUp() {
        $this['middle'] = new MiddleView();
    }

    function paint() {
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Scope Example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1 align="center">Scope Example</h1>
<p><br />
This is an example using the scope tag and the import tag to illustrate
how variable scoping works inside of a template file.</p>
<p>
<TABLE border="1">
    <TR>
        <TD>{$Animal} = <?php echo $this->myScope->model->Animal ?></TD>
        <TD>{$^Animal} = <?php echo $this->parentScope->model->Animal ?></TD>
        <TD>{$#Animal} = <?php echo $this->rootScope->model->Animal ?></TD>
    </TR>
    <TR>
        <TD>{$Food} = <?php echo $this->myScope->model->Food ?></TD>
        <TD>{$^Food} = <?php echo $this->parentScope->model->Food ?></TD>
        <TD>{$#Food} = <?php echo $this->rootScope->model->Food ?></TD>
    </TR>
</TABLE>
<blockquote> This is inside a Data Space tag
<?php $this->renderChildren(); ?>
</blockquote>
</body>
</html><?php
    }

}

$view = new MyView();
$view->setModel(array(
    'Animal' => 'Rabbit',
    'Food' => 'Carrot'));
$view['middle']->setModel(array(
    'Animal' => 'Monkey',
    'Food' => 'Banana'));
$view['middle']['inner']->setModel(array(
    'Animal' => 'Worm',
    'Food' => 'Apple'));
$view->display();

?>
