Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Events\Events;
|
||||
use CodeIgniter\Exceptions\FrameworkException;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Application Events
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
Events::on('pre_system', static function () {
|
||||
// Boot Eloquent ORM
|
||||
bootEloquent();
|
||||
});
|
||||
|
||||
/**
|
||||
* Bootstrap Eloquent ORM with database configuration from environment
|
||||
*/
|
||||
function bootEloquent(): void
|
||||
{
|
||||
$capsule = new Capsule();
|
||||
|
||||
$capsule->addConnection([
|
||||
'driver' => 'mysql',
|
||||
'host' => $_ENV['DB_HOST'] ?? '127.0.0.1',
|
||||
'database' => $_ENV['DB_NAME'] ?? '',
|
||||
'username' => $_ENV['DB_USER'] ?? '',
|
||||
'password' => $_ENV['DB_PASS'] ?? '',
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
]);
|
||||
|
||||
// Make this Capsule instance available globally via static methods
|
||||
$capsule->setAsGlobal();
|
||||
|
||||
// Setup the Eloquent ORM
|
||||
$capsule->bootEloquent();
|
||||
}
|
||||
Reference in New Issue
Block a user