简体   繁体   English

尝试获取字段值时出现“数组到字符串转换错误”

[英]"Array to string conversion error" when trying to get the values of fields

I'm trying to make datatables as server-side processing.我正在尝试将数据表作为服务器端处理。 It somehow worked.它以某种方式起作用。 I wanted to pass the fields to ajax file and use them to get the data.我想将字段传递给 ajax 文件并使用它们来获取数据。 I made the fields name as a string to divide them using a delimiter character.我将字段名称设为字符串以使用分隔符分隔它们。 Then I passed the string and get it and made them as an array.然后我传递了字符串并获取它并将它们作为一个数组。 Problem is, "Array to string conversion error" displays when I try to get the values through them.问题是,当我尝试通过它们获取值时会显示“数组到字符串转换错误”。

PHP block in October CMS 10 月 CMS 中的 PHP 块

<?php

function onStart()
{
    $this['tableName'] = 'BYAPPS_apps_data';
    $this['fields'] = "app_id|app_name|app_ver|byapps_ver";
}
?>

Javascript in October CMS(same page as the php block) 10 月 CMS 中的 Javascript(与 php 块相同的页面)

  var table = $('#' + tableId).DataTable( {
      processing: true,
      serverSide: true,
      ajax: {
          url: '/ajax?tb={{ tableName|raw() }}&fd={{ fields|raw() }}',
          type: 'GET',
          error: function(e) {
            console.log(e);
          }
      },
      paging: true,
      pageLength: 50,

Ajax page Ajax 页面

function onStart()
{
   $table = $_GET['tb'];
   $length = $_GET['length'];
   $start = $_GET['start'];
   $fields = explode("|", $_GET['fd']);

   $result = DB::table($table)->skip($start)->limit($length)->get();
   $data = array();

   foreach($result as $row) {
      $sub_array = array();

      for ($i = 0; $i < count($fields); $i++) {

        echo "<script>console.log('".$fields[$i]."')</script>";
        $sub_array[] = $row->$fields[$i];

      }
      $data[] = $sub_array;
   }

The $fields[$i] shows 'app_id', 'app_name'... But I don't know why I can't get the values through like this. $fields[$i]显示“app_id”、“app_name”……但我不知道为什么我不能像这样获取值。 $row->$fields[$i] How can I fix this? $row->$fields[$i]我该如何解决这个问题?

$result contains these kinda data like below. $result 包含这些类似下面的数据。

object(October\Rain\Support\Collection)#947 (1) { ["items":protected]=> array(50) { [0]=> object(stdClass)#949 (88) { ["idx"]=> int(1) ["o_idx"]=> int(0) ["mem_id"]=> string(20) "epicegirls@naver.com" ["app_id"]=> string(10) "epicegirls" ["recom_id"]=> string(6) "byapps" ["app_cate"]=> string(2) "01" ["app_process"]=> int(8) ["app_name"]=> string(12) "에피스걸" ["service_type"]=> string(3) "biz" ["server_group"]=> string(1) "2" ["apps_type"]=> string(19) "안드로이드+iOS" ["app_os_type"]=> string(7) "android" ["byapps_ver"]=> string(3) "2.1" ["app_ver"]=> string(3) "1.6" ["app_ver_ios"]=> string(3) "1.1" ["app_build"]=> string(0) "" ["app_build_ios"]=> string(0) "" ["app_lang"]=> string(2) "ko" ["packagename"]=> NULL ["bundleid"]=> NULL ["app_android_url"]=> string(66) "http://play.google.com/store/apps/details?id=com.epicegirls.byapps" ["app_ios_url"]=> string(58) "http://itunes.apple.com/kr/app/episeugeol/id648794513?mt=8" ["app_icon"]=> string(14) "1366951826.png" ["noti_gcm"]=> string(39) "AIzaSyB4uXkiTltMx3yjQNo26uyfpopMB8vpd94" ["noti_ios"]=> string(14) "1369015681.pem" ["noti_gcm_num"]=> NULL ["noti_fcm_num"]=> NULL ["noti_ios_cerp"]=> string(10) "byapps2013" ["push_server"]=> string(7) "default" ["developer_account"]=> string(1) "N" ["developer_info"]=> string(2580) "- 개발자아이디: 

尝试这个

$sub_array[] = $row->{$fields[$i]};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用数据库中的值获取下拉菜单,但将数组转换为字符串错误(YII2) - Trying to get dropdown menu with values from database but getting array to string conversion error (YII2) 数组中的字符串仅在尝试获取单个值时才返回 undefined? - String in array returning undefined only when trying to get single value? 注意:将数组从php转换为javascript时,数组到字符串的转换错误 - Notice: Array to string conversion error when converting array from php to javascript 尝试从数组调用返回字符串时出错 - Error when trying to return a string with calls from array 如何在PHP中删除数组到字符串转换的错误 - how to remove the array to string conversion error in php Laravel 错误异常。 数组到字符串的转换 - Laravel Error Exception. Array to string Conversion Outlook 加载项在尝试获取“to”值时返回错误 5001 - Outlook add-in returns error 5001 when trying to get the "to" values 尝试从数据库中获取值时出现 Javascript“未定义”错误 - Javascript 'undefined' error, when trying to get values from database 尝试将数据导出到 reactJS 中的 CSV 时,获取错误数据应该是“字符串”、“数组数组”或“对象数组” - Getting Error Data should be a "String", "Array of arrays" OR "Array of objects" when trying to export data to CSV in reactJS 数组到字符串的转换不起作用 - Array to string conversion not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM