Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
Hi, The connection name is "default" but the output message is "There is no source available, please add at least one in the settings()"
This is my code in report:
<?php
require APPPATH."../vendor/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Join;
use \koolreport\processes\Limit;
use \koolreport\processes\Sort;
//Define the class
class Lot extends \koolreport\KoolReport
{
use \koolreport\codeigniter\Friendship;
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
use \koolreport\export\Exportable;
use \koolreport\bootstrap4\Theme;
function defaultParamValues()
{
return array(
"lot"=>0
);
}
function bindParamsToInputs()
{
return array(
"lot"
);
}
public function setup()
{
$this->src('default') //<==
->query("SELECT name lot FROM lots ORDER BY catchdate DESC")
->pipe($this->dataStore('lots'));
If I put the database settings this report works but I have to put it in every report
Regards
Hi Koolreport,
I modified codeigniter Friendship.php to capture default database in codeigniter 4.
Maybe in the next update you could add
Regards
<?php
namespace koolreport\codeigniter;
use \koolreport\core\Utility;
trait Friendship
{
public function __constructFriendship()
{
//assets folder
$assets = Utility::get($this->reportSettings, "assets");
if ($assets == null) {
$document_root = Utility::getDocumentRoot();
$script_folder = str_replace("\\", "/", realpath(dirname($_SERVER["SCRIPT_FILENAME"])));
$asset_path = $script_folder . "/assets";
$asset_url = Utility::strReplaceFirst($document_root, "", $script_folder) . "/assets";
if (!is_dir($asset_path . "/koolreport_assets")) {
if (!is_dir($asset_path)) {
mkdir($asset_path, 0755);
}
mkdir($asset_path . "/koolreport_assets", 0755);
}
$assets = array(
"url" => $asset_url . "/koolreport_assets",
"path" => $asset_path . "/koolreport_assets",
);
$this->reportSettings["assets"] = $assets;
}
////////////////////////////////////start\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//If codeigniter 4 then load default database <====
if(file_exists(APPPATH . 'Config/App.php')){
$db = \Config\Database::connect();
$dataSources = array(
"default"=>array(
"connectionString"=>"mysql:host=$db->hostname;dbname=$db->database",
"username"=>$db->username,
"password"=>$db->password,
"charset"=>$db->charset
),
);
$this->reportSettings["dataSources"] = $dataSources;
}
return;
////////////////////////////////////end\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if (!file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/database.php')
&& !file_exists($file_path = APPPATH . 'config/database.php')) {
return;
}
include $file_path;
$dbSources = array();
foreach ($db as $name => $dbconfig) {
$dbSources[$name] = array(
"class" => CIDataSource::class,
"name" => $name,
);
}
$dataSources = Utility::get($this->reportSettings, "dataSources", array());
$this->reportSettings["dataSources"] = array_merge($dbSources, $dataSources);
}
}
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo