0

这可能是一个愚蠢的问题,但我是 koolreport 的新手,而且我从未使用过 PHP。

我正在尝试执行一个简单的程序,该程序可以以表格形式提取存储在 MongoDB 集合中的所有数据。我正在关注 koolreport 网站上提供的示例程序。他们已经清楚地提到了如何从非对象列类型中提取数据。哪个工作得很好。但是程序无法从继承的列中获取数据。它说“致命错误:未捕获的错误:MongoDB\Model\BSONDocument 类的对象无法转换为字符串”。

我寻找解决这个问题的方法。我遇到了将 MongoDB 文档转换为 PHP 以便数据呈现的过程。但它一直显示同样的错误。

MongoDB 集合(Employee)结构:

        {
         "name" : string,
         "tech" : {
            "name" : string
              }
         }

以下是代码文件。

  1. 索引.php

    <?PHP
    require_once "../vendor/autoload.php";
    
    require_once "demoReport.php";
    
    $report = new demoReport;
    
    $report->run()->render();
    
    ?>
    

2.demoReport.php

        <?PHP
        class demoReport extends \koolreport\KoolReport
        {
            public function settings()
            {
                return array(
                    "dataSources"=>array(       
                        "data"=>array(
                            "class"=>'\koolreport\mongodb\MongoDataSource',
                            "connectionString"=>"mongodb://localhost",
                            "database"=>"Employee"
                        ),
                    )
                );
            }
            public function setup()
            {
                $this->src('data')
                ->query(array (
                    "collection"=>"Employee",
                    "option"=>[
                        "projection"=>[
                            "name"=>1,
                            "tech.name"=>1
                        ]
                    ]
                ))
                ->pipe($this->dataStore('result'));
   
            }
        }
  1. 演示报告.view.php

         <HTML>
         <head>
                 <title> fetching data</title>
             </head>
             <body>
                 <?php
                     \koolreport\widgets\koolphp\Table::create(array(
                         "dataSource"=>$this->dataStore('result')
                         )
                     );
                 ?>
             </body>
         </html>
    

这是错误:

致命错误:未捕获的错误:MongoDB\Model\BSONDocument 类的对象无法转换为字符串
C:\xampp\htdocs\demo\vendor\koolreport\core\src\widgets\koolphp\Table.tpl.php:138 堆栈跟踪:#0 C:\xampp\htdocs\demo\vendor\koolreport\core\src\ core\Widget.php(736): include() #1 C:\xampp\htdocs\demo\vendor\koolreport\core\src\widgets\koolphp\Table.php(431): koolreport\core\Widget->template ('Table', Array) #2 C:\xampp\htdocs\demo\vendor\koolreport\core\src\core\Widget.php(676): koolreport\widgets\koolphp\Table->onRender() #3 C :\xampp\htdocs\demo\vendor\koolreport\core\src\core\Widget.php(764): koolreport\core\Widget->render() #4 C:\xampp\htdocs\demo\demoReport\demoReport。 view.php(10): koolreport\core\Widget::create(Array) #5 C:\xampp\htdocs\demo\vendor\koolreport\core\src\KoolReport.php(502): include('C:\ xampp\htdocs...') #6 C:\xampp\htdocs\demo\demoReport\index.php(8): koolreport\KoolReport->render() #7 {main} 抛出 C:\xampp\htdocs\demo\vendor\koolreport\core\src\widgets\koolphp\Table.tpl.php 在第 138 行

在输出中,id 和 name 被正确获取,但在 tech 列中,出现了这个错误。请帮我解决这个错误。我试图解决它好几天。

4

0 回答 0