[英]"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.