Doctrine integration |
Hello jasonzig,
Quote:Maybe it's better in an another thread ? Documentation: Doctrine: https://www.doctrine-project.org/project...h-doctrine 1) SERVER: I'm using php 7.2.9, Nginx, MariaDb, phpmyadmin and composer. 2) CODEIGNITER: I used composer to install codeigniter, you can find more information: https://codeigniter4.github.io/userguide...poser.html Code: composer create-project codeigniter4/appstarter project-root -s rc => You should have a welcome page on your browser => I'm always also putting CodeIgniter in dev mode (Up to You) 3) INSTALLATION OF DOCTRINE: Composer to add doctrine: => composer.json (should be at the base of your project) https://www.doctrine-project.org/project...ject-setup You need to add: Code: { after in the console: 'composer install' and 'composer update' 4) CREATING THE DOCTRINE LIBRARIE: (FOR CI) =>App/Libraries/Doctrine.php PHP Code: <?php 5) CREATING THE FOLDERS: You need to create in the Models folder the following folders: 'Entities' => Models/Entities 'Proxies' => Models/Proxies 'Mappings' => Models/Mappings => The one you will use to create your tables 6) CREATING THE COMMAND LINE DOCTRINE: => In your App folder App/Doctrine.php PHP Code: <?php I'm also using a shortcut =>App/doctrine PHP Code: #!/usr/bin/env php 7) TEST THE COMMAND LINE: If everything is well setup you should be able to call doctrine in your console: By a simple 'php doctrine' (if you using the shortcut) or by a 'php Doctrine.php' PHP Code: php doctrine And you should get a : Code: Doctrine Command Line Interface 2.6.4-DEV 8) DOCTRINE AS A SERVICE: Quote:Special thanks to: MGatner and InsiteFx => App/Config/Services.php You need to edit your services.php to add doctrine as a serviceStill need some optimization i guess) PHP Code: class Services extends CoreServices 9) TEST : Now in your BaseController you can call this service and make a test: PHP Code: public function index() 10) HOW TO USE IT: Let's Create a test table: A)Generate an entity: In the folder 'Mappings' you can create a file called 'test' in yml: =>app/Models/Mappings/Entities.Test.dcm.yml Entities.Test.dcm.yml (Will be our 'test' table) Code: Entities\Test: B) Generate the class: Code: php doctrine orm:generate-entities Models C) Generate the proxies: Code: php doctrine orm:generate-proxies D) Create the table in our Dbb: Code: php doctrine orm:schema-tool:create Now you can just use doctrine in your controllers to get back information to update to insert etc: Quote:Check the Doctrine documentation for more information E) Get back the info: PHP Code: public function index() If there is something not clear or if you see something to change just let me know It's will be a pleasure to help you Regards,
What a thorough write up! Thanks to ScientiFist for sharing. This does make me realize how involved Doctrine is. I’ve never used it, and it seems like it overlaps with quite a bit of framework code and function. Do you mind me asking why everyone wants it? What do you use Doctrine for?
Hello! Thanks for your tutorial, it helped me a lot!
For my part, I used Entities present in CI modules (folder App\Modules) for the mapping. (I can provide some code snippets if you are interested) Everything works without problems, however, I was wondering if it was possible to access Doctrine commands on a remote host (OVH for example) for shared servers (in SSH maybe)? Or if we could simply call the commands of Doctrine (update DB schema, ...) without terminal access? Thanks again! EDIT: I ended up figuring out how to do it if someone is interested: PHP Code: <?php Just call these functions to run Doctrine commands directly from a PHP page (without using a terminal). As a reminder, my Entities are not in the CI4 basic Models\Entities folder. I use modules that have the following structure: app\Modules\{module_name}\Entities. Here is my Libraries\Doctrine.php class: PHP Code: <?php So, I do not use a YAML file for mapping but annotations directly in my Entities. Hope this can help someone else! Have a nice day!
Hello,
Very interested by this solution, so i tried it. But Doctrine version is higher and code exposed here does not work anymore. So i picked code for App\Libraries\doctrine.php in doctrine "installation and configuration" page (didn't kept Code: require_once "vendor/autoload.php"; PHP Code: namespace App\Libraries; No error messages but, in home.php controller PHP Code: $entityManager = service('doctrine'); Can someone help ? Will tatter/relations be modified to comply to the requirements of v4.5.1 version? Thanks Eric
@foxbille Did you define the doctrine service in Config\Services?
yes i did!
PHP Code: namespace Config; @kenjis By the way, do you plan to update your kenjis/codeigniter-doctrine for codeigniter 4?
No, because there is already https://github.com/daycry/doctrine
(05-13-2024, 06:57 PM)kenjis Wrote: No, because there is already https://github.com/daycry/doctrine okay |
Welcome Guest, Not a member yet? Register Sign In |