Welcome Guest, Not a member yet? Register   Sign In
Integration doctrine to codeigniter 4
#8

(This post was last modified: 04-11-2020, 06:00 AM by ufhy.)

Maybe like this:

app\Libraries\Doctrine.php

PHP Code:
<?php namespace App\Libraries;

use 
Doctrine\ORM\EntityManager;
use 
Doctrine\ORM\Tools\Setup;

class 
Doctrine
{
    public $em null;

    public function __construct()
    {
        $dbConfig config('Config\Database');
        $db $dbConfig->{$dbConfig->defaultGroup};

        $isDevMode ENVIRONMENT !== 'production';
        $proxyDir null;
        $cache null;
        $useSimpleAnnotationReader false;

        $config Setup::createAnnotationMetadataConfiguration(
            [APPPATH 'Entities'],
            $isDevMode,
            $proxyDir,
            $cache,
            $useSimpleAnnotationReader
        
);

        $connection = [
            'driver'   => $db['DBDriver'] === 'MySQLi' 'mysqli' 'pdo_mysql',
            'user'     => $db['username'],
            'password' => $db['password'],
            'host'     => $db['hostname'],
            'dbname'   => $db['database'],
            'charset'  => $db['charset'],
        ];

        $this->em EntityManager::create($connection$config);
    }


cli-config.php (folder root project)

PHP Code:
<?php
use App\Libraries\Doctrine;
use 
Doctrine\ORM\Tools\Console\ConsoleRunner;

error_reporting(E_ALL);

$pathsPath './app/Config/Paths.php';

require 
$pathsPath;
$paths = new Config\Paths();

// Location of the framework bootstrap file.
$app = require rtrim($paths->systemDirectory'/ ') . '/bootstrap.php';
$doctrine = new Doctrine();

return 
ConsoleRunner::createHelperSet($doctrine->em); 

and now you can exec command 
Code:
vendor/bin/doctrine
Reply


Messages In This Thread
Integration doctrine to codeigniter 4 - by maky - 06-09-2018, 12:51 PM
RE: Integration doctrine to codeigniter 4 - by ufhy - 04-11-2020, 05:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB