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\UnknownPropertyExceptionGetting unknown property: frontend\models\Country::label_img
原因:缺少label-img这个字段
解决方法:在rule规则中写入这个字段,在数据库中加上这个字段