• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integration doctrine to codeigniter 4

#1
I have installed doctrine with composer and added Doctrine.php to libraries using tutorial on next link
codeigniter and doctrine

and I try this:


PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
App\Libraries\Doctrine;

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

class 
Home extends Controller {

public function 
test {

            
$rsm = new ResultSetMapping();
 
           
            
            $query 
$entityManager->createNativeQuery('SELECT * FROM test'$rsm);
 
           
            
            $users 
$query->getResult();
 
           print_r($users);

       }



Autoload


PHP Code:
public $classmap = [
 
           'Test' => APPPATH 'libraries/Test.php',
 
           'Twig' => APPPATH 'libraries/Twig.php',
 
           'Doctrine' => APPPATH 'libraries/Doctrine.php',
 
       ]; 


and I get error: Undefined variable: entityManager

This is only the test for me.
Reply

#2
You said where to find EntityManager, but didn't instantiate anything. $entityManager is null.
Are you perhaps missing $entityManager = new EntityManager(); ?
Reply

#3
(06-09-2018, 01:53 PM)ciadmin Wrote: You said where to find EntityManager, but didn't instantiate anything. $entityManager is null.
Are you perhaps missing $entityManager = new EntityManager(); ?

codeigniter and doctrine
Reply

#4
Hmmm - right in the link you sent, it says ...
Code:
// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);

I don't see anything like that in your code, and stand by my original answer.
You are also not setting up the rest of the stuff in the constructor, per the article link.
Reply

#5
This is not for CodeIgniter 4 forums ..

$entityManager what is that variable, where you use it and how do you get it ? The error you get is simple PHP error that you are using undefined variable .. (there is nothing set to $entityManager)

At the tutorial it is simple written that you must use :
Code:
$em = $this->doctrine->em;

Is that what you use for $entityManager ?
Best VPS Hosting : Digital Ocean
Reply

#6
Simple hes calling the Entity Manager in his query but it has not yet been initiated
like @ciadmin has said...
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.