KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dashboard Datasource not found #2407

Closed Niall McGuirk opened this topic on on Oct 28, 2021 - 7 comments

Niall McGuirk commented on Oct 28, 2021

I've added a SelectBox to a Dashboard Board. However, it can't find the data source, despite the php file being present.

The error is stating that it can't find the Datasource, despite my stating it in the 'use' list. It also couldn't find the Automaker.php datasource.

//SelectDemo.php

<?php

//namespace demo\inputs;

use \koolreport\dashboard\inputs\Select;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \demo\DealHack; //EXPLCITLY LOCATING Dealhack DataSource
use \demo\AutoMaker;

class SelectDemo extends Select
{
//    protected function onCreated()
//    {
//        $this->defaultOption(["--"=>null]);
//    }

    protected function dataSource()
    {
        return DealHack::table("tbl_company") //LINE 20 CAUSING ERROR
                ->select("CompanyName")
                ->limit(5);
        
    }

//    protected function actionChange($request, $response)
//    {
//        $this->sibling("Result")->update();
//    }

    protected function fields()
    {
        return [
            Text::create("CompanyName"),
        ];
    }
}

DealhackBoard.php

<?php

use \koolreport\dashboard\Dashboard;

use \koolreport\dashboard\containers\Row;
use \koolreport\dashboard\containers\Panel;
use \koolreport\dashboard\widgets\Text;
use \koolreport\dashboard\widgets\StateHolder;

use \koolreport\dashboard\menu\MenuItem;
use \koolreport\dashboard\Client;
use \koolreport\dashboard\containers\Html;

use \koolreport\dashboard\Container;
use \koolreport\dashboard\inputs\Button;


class DealhackBoard extends Dashboard
{
    protected function widgets()
    {
        return [
            SelectDemo::create(),
            Html::label("TextBox")->style("font-weight:bold"),
            TextBoxDemo::create(),
            
            DealhackTable::create(),
            ProductByLine::create(),
            
            
                
            
        ];
    }
}


?>
KoolReport commented on Oct 28, 2021

May I know the location of App.php and DealHack.php, also please post the file DealHack.php (you may remove sensitive db information).

Niall McGuirk commented on Oct 29, 2021

The App.php and all other files are in one directory, at present, to minimise complexity.

Dealhack.php

<?php

use \koolreport\dashboard\sources\MySQL;

class DealHack extends MySQL
{
    protected function connection()
    {
        return [
             "connectionString"=>"mysql:host=localhost;dbname=dealhack",
             "username"=>"*******",
             "password"=>"*******",
             "charset"=>"utf8"
         ];
    }
}
KoolReport commented on Oct 29, 2021

I see, so you do not use any namespace for DealHack class. So you can remove the use \demo\DealHack; line. Let me know if it work.

Niall McGuirk commented on Oct 29, 2021

Thank you very much, Removing the use demo/Dealhack from SelectDemo has worked.

Niall McGuirk commented on Oct 29, 2021

Can I clarify, if I put the files in a folder, do I just use the namespace set to demo/<filename>, and use demo/<foldername>/<filename>?

KoolReport commented on Oct 29, 2021

Previously, if you need to include any file in php, you need to manually use require() or include() method and specify exactly location of the file. For example (if you have a folder name "sources" containing the DeadHack.php needed to be included), you do

<?php
//App.php
include dirname(__FILE__)."/sources/DeadHack.php";
use sources\DeadHack;

And problem is there is alot of file needed to be included and cause trouble. So we make an auto file included. If the specify the name like this in App.php:

<?php
//App.php
use sources\DeadHack;

the Dashboard app will looked for class sources\DeadHack in the file with location ./sources/DeadHack.php. And in that DeadHack.php, you need to specify namespace sources;


In your case, when you specified use demo\DeadHack, system will look for the file ./demo/DeadHack.php which is not found. That's why I tell you to remove it.

Hope my explanation is good.

Niall McGuirk commented on Oct 29, 2021

Ok, That makes sense. Thank you for the help.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Dashboard