public function testViewAction( )
{
$data["title"] = "hello,world";
$data["content"] = "are you there ";
$data["friends"] = array(
array( "id" =>"1" , "name"=>"yqr" ),
array( "id"=>2 , "name"=>"jim" )
);
$this->view->display( "index/testView.php" , $data , false );
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> <?php echo $title; ?></title>
</head>
<body>
<h1> <?php echo $title?> </h1>
<?php echo $content ?>
<hr/>
<h2>My Friends</h2>
<table>
<tr><th>id</th><th>name</th></tr>
<?php for( $i=0; $i< count( $friends ) ; $i++ ): ?>
<tr>
<td> <?php echo $friends[$i]["id"] ?> </td>
<td> <?php echo $friends[$i]["name"] ?> </td>
</tr>
<?php endfor; ?>
<? echo "hello,short tag!"; ?>
</table>
</body>
</html>
基中蓝色的变量是从testViewAction()中$data数组的下标中转化而来的。
比如 视图中的 $title 对应 动作testViewAction中的 $data["title"]。这点应该不难理解。
public static View::assign( string $varName , mixed $data );
设置视图变量。
$varName 要设置的变量名。
$data 变量名对应的数据。