Doctrine integration |
Hi,
I'm trying to integrate doctrine 2.6.4 with CI 4. Doctrine was installed via composer. App/Libraries/Doctrine.php Code: <?php App/Doctrine.php Code: <?php Everything is working with the console i can render Entities via YML Mappings so everything is connected to my db and so on Then i'm just calling doctrine in the Base controller in CI 3 i was using the load->library Quote:require APPPATH.'/Libraries/Doctrine.php'; And here is the problem i can't initiate the entityManager i tried in different way but im all the time getting a undefined property or undefinedclass : PHP Code: <?php namespace App\Controllers; I know it's maybe complicated or me who's missing something but would be amazing any kind of help, a lot of users of CI are using doctrine as an orm and would really help me for my future project
THere's probably going to be a lot of collision that will have to be handled. I haven't ever used Doctrine, but from your example above it looks like Doctrine might need its own APPPATH? That would cause problems with the framework for sure. I would recommend looking into Composer integration for starters, as that will handle the autoloading. Also read up on namespaces and how CI4 is different than CI3 when it comes to loading and the super object (e.g. you can't use $this->doctrine):
https://codeigniter4.github.io/CodeIgnit...dules.html I guess I should add that I have a module to help with adding relationship loading to CI4. I'm not a fan of ORM but this might get at some of the eager/lazy loading and easy access that ORMs provide: https://github.com/tattersoftware/codeig...-relations Note that there's a major release in the works on branch develop, so the current stable release will differ some.
Did you read the documentation?
You need to create an instance of the Entity Manager before you can use it. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Also to mention this package which hasn’t been touched in a while but is the best CodeIgniter 4 style ORM I have seen worked on
https://github.com/hlohrenz/CI4-Relation...ry-Builder
(11-17-2019, 04:50 AM)InsiteFX Wrote: Did you read the documentation?Here was the problem i didn't create the instance... I added the namespace for my Doctrine.php in libraries PHP Code: <?php Thank you MGatner ! I didn't saw this way to load a library PHP Code: public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) Last question my Home controller extend from this BaseController. So how i can get my back my $em object in my controllers from this initController?
Since it seems like Doctrine already works very nicely with namespaces, and supplies a singular reference and object, I would recommend writing a service definition for it. That time you can load it anywhere you want with `service(‘doctrine’)` and the services will take care of continuity for you.
(11-18-2019, 05:31 AM)MGatner Wrote: Since it seems like Doctrine already works very nicely with namespaces, and supplies a singular reference and object, I would recommend writing a service definition for it. That time you can load it anywhere you want with `service(‘doctrine’)` and the services will take care of continuity for you. Amazing thank you a lot, everything is working So i added doctrine as a service PHP Code: class Services extends CoreServices and then im calling it like this in my Home controller PHP Code: public function index() Just small question there is not a way to call this service for all my controllers instead of calling it each time i want to use it? Quote:Ps: I will send all the files and the explanation how i got doctrine working with code igniter after i received some PM about it
That’s a good start! I’d recommend adding a getShared clause, as this is what helps your service save resources by returning a common instance. If I’m understanding Doctrine correctly, you don’t want to load a fresh instance on every call. Check out Lonnie’s examples in his auth library:
https://github.com/lonnieezell/myth-auth...rvices.php There should be no need to carry around the $em object, but if you really find yourself needing it all the time in controllers you can load it in BaseController ($this->em = $em) and then extend that.
Here is it with the getshared: (Hope is working like that)
PHP Code: class Services extends CoreServices But i didn't get what do you meant with the '$em' ? (11-18-2019, 10:34 AM)ScientiFist Wrote:(11-18-2019, 05:31 AM)MGatner Wrote: Since it seems like Doctrine already works very nicely with namespaces, and supplies a singular reference and object, I would recommend writing a service definition for it. That time you can load it anywhere you want with `service(‘doctrine’)` and the services will take care of continuity for you. Hello ScientiFist, Would you be willing to post instructions for using your Doctrine implementation? I am interested in trying it out! I've noticed the CodeIgniter4 Playground has Doctrine installed in the vendor directory after performing a Code: composer update Best regards, Jason Ziegler (Using CodeIgniter since 1.x)
|
Welcome Guest, Not a member yet? Register Sign In |