zoukankan      html  css  js  c++  java
  • yii2 对象跟数组输出数据到view视图方法

    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 – yiiaseUnknownPropertyException

    Getting unknown property: frontendmodelsCountry::label_img

    原因:缺少label-img这个字段

    解决方法:在rule规则中写入这个字段,在数据库中加上这个字段

  • 相关阅读:
    bootmgr is missing
    【转】ahci和IDE的区别
    win10系统故障代码:0xc000014c
    c++小数点后舍入
    关于类里再声明自身类实例的思考
    Java集合
    Python图片转字符画
    102. Binary Tree Level Order Traversal
    1041. Robot Bounded In Circle
    144. Binary Tree Preorder Traversal
  • 原文地址:https://www.cnblogs.com/yszr/p/7894803.html
Copyright © 2011-2022 走看看