我正在尝试将外部数据库数据显示在自定义管理选项卡上,但收到错误。可以帮助我解决此问题。我可以从外部数据库中获取数据但是当我将它传递给GridField时,它会给我这个错误。
“get_class()期望参数1为对象,给定数组为”
这是我的代码
public function getList() {
$externalDB = $object = Injector::inst ()->create ( 'ExternalDatabase' );
$results = $externalDB->query ( 'SELECT "Course" FROM "Courses"' );
$list = ArrayList::create ();
foreach ( $results as $row ) {
$list->push ( $row ) ;
}
return $list;
}
我有ExternalDatabase类来解析我的查询并返回结果。
答案 0 :(得分:1)
不要直接推动行,而是尝试
public static void printCategories(String string) {
int i = 0;
while (true) {
int found = string.indexOf("category", i);
if (found == -1)
break;
int start = found + 9; // start of actual category --> incremented one position to omit `:`
int end = string.indexOf(" ", start); // added space to split the word after category
System.out.println(string.substring(start, end));
i = end + 1; // advance i to start the next iteration
}
}