Closed ahmaddzidan closed 5 months ago
Can you show me a working example?
Bellow is my working code so far:
Codeigniter4Adapter.php
class Codeigniter4Adapter extends DBAdapter
{
protected $db;
protected array $config;
public function __construct($config = null)
{
if ($config != null) {
$this->config = $config;
}
if (!isset($this->config['DBGroup']))
{
$this->config['DBGroup'] = 'default';
}
}
public function connect()
{
$this->db = \Config\Database::connect($this->config['DBGroup']);
return $this;
}
PageModel.php
public function datatables()
{
$dt = new Datatables(new Codeigniter4Adapter(['DBGroup' => $this->DBGroup]));
$builder = $this->db->table($this->table . ' page');
$builder->select('page.id, page.title, template.name, page.status');
$builder->join('web_page_templates template', 'template.id=page.template_id','left');
$builder->orderBy('page.id DESC');
$dt->query($builder);
return $dt->generate()->toJson();
}
I add config array variable to Codeigniter4Adapter and pass DBGroup config via construct config parameter.
Thanks, I will update it tonight.
okay, thanks .
Hey There..
I have a problem when i using this library with multiple database group with different schema, i am using postgresql database (14.7) and Codeigniter 4 (4.5.0) as PHP framework.
i have been research through google but i cant find the suitable answer. Bellow is example of my code:
and produce error :
pg_query(): Query failed: ERROR: relation 'web_pages' does not exist LINE 2: FROM 'web_pages''page'
i think the error is explain that table not found in current default schema. when i check Codeigniter4Adapter, i think this library is not have options to use different database group, instead use default group ?
But after i try adding the db group inside connect() with group 'website', everything works and the error is gone.
Kind regards