public function actionJiekou(){
$url = 'http://wap.guoshihui.com/_static/wap/video/startVideo.mp4';
//數組數據
$data = array(
'status' => '200',
'message' => '數組數據獲取成功',
'url' => $url,
);
//對象數據
$res = new Country();
$res->status = '888';
$res->message = '對象方法';
$res->shuchu = '對象方式調用成功';
// return json_encode($data);
$jiekou = json_encode($data);
return $this->render('jiekou',[
'value' => $data,
'duixiang' => $res,//渲染模版這里可以輸出無數個數據到頁面中去
]);
}
前台頁面
$this->title = 'Create Country';
$this->params['breadcrumbs'][] = ['label' => '接口', 'url' => ['country/jiekou']];
$this->params['breadcrumbs'][] = $this->title; 這些是面包屑導航以及標題
?>
<div class="country-create">
<?= Html::encode($this->title) ?>
<h1>數組方法輸出</h1>
<?=$value['message']?><br>
<?=$value['url']?><br>
<h1>對象方法輸出</h1>
<?= Html::encode($duixiang->status) ?><br>
<?= Html::encode($duixiang->message) ?><br>
<?= Html::encode($duixiang->shuchu) ?><br>
</div>
yii報錯
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: frontend\models\Country::label_img
原因:缺少label-img這個字段
解決方法:在rule規則中寫入這個字段,在數據庫中加上這個字段
