### Models, Views, Controllers
>[info] http://www.yiichina.com/doc/guide/2.0/structure-overview

### 向View傳遞Model
>[info] 項目代碼下載 https://git.oschina.net/radarxu/yii-demo
1、簡單模型
frontend\controllers\SiteController.php
~~~ php
public function actionAbout()
{
$location = '中國,上海';
return $this->render('about', ['location' => $location]);
}
~~~
frontend\views\site\about.php
~~~ html
/* @var $location string */
<p>地址: <?= $location ?></p>
~~~
2、數組模型
frontend\controllers\SiteController.php
~~~ php
public function actionAbout()
{
$location = ['city' => '上海', 'country' => '中國'];
return $this->render('about', ['location' => $location]);
}
~~~
frontend\views\site\about.php
~~~ html
/* @var $location array */
<p>城市: <?= $location['city'] ?></p>
<p>國家: <?= $location['country'] ?></p>
~~~
3、復雜模型
frontend\controllers\SiteController.php
~~~ php
public function actionAbout()
{
$model = new AboutModel();
$model->name = '徐飛';
$model->city = '上海';
$model->country = '中國';
return $this->render('about', ['model' => $model]);
}
~~~
frontend\views\site\about.php
~~~ html
/* @var $model frontend\models\AboutModel */
<p>姓名: <?= $model->name ?></p>
<p>城市: <?= $model->city ?></p>
<p>國家: <?= $model->country ?></p>
~~~
4、多個模型
frontend\controllers\SiteController.php
~~~ php
public function actionAbout()
{
$name = '徐飛';
$city = '上海';
$country = '中國';
return $this->render('about', ['name' => $name, 'city' => $city, 'country' => $country]);
}
~~~
frontend\views\site\about.php
~~~ html
/* @var $name string */
/* @var $city string */
/* @var $country string */
<p>姓名: <?= $name ?></p>
<p>城市: <?= $city ?></p>
<p>國家: <?= $country ?></p>
~~~