Bootstrap.php
Container class
Container definition
subClass use container
I wanted to use some essential 3rd party libraries (composers), and to ease the dependency with inate I deployed a PHP-DI container.
Is my method correct? Am I misunderstanding PHP-DI when injecting dependencies into the Welcome class like the code above?
Is the way I am using this third party library correct?
3 years ago
3 years ago
#1
3 years ago
#2
Here's a video tutorial that might be helpful:
https://www.youtube.com/watch?v=oVSDrG4ibrI
https://www.youtube.com/watch?v=oVSDrG4ibrI
3 years ago
#3
Xin chào quangquoc,
As DC has suggested, take a look through the video he posted on the subject of using Packagist with Trongate. It's quite simple to do and use.
For me, it's always about 'how it makes you feel' and 'if you feel good' then that usually is the correct way to do it, so don't let anyone tell you 'this is how you should do it' or 'if you're not doing it my way, you're doing it wrong'. I hate those tutorials or people who push their agenda on others.
But in saying that, it's always a good idea to have a look at how Trongate loads and in what order so you can make the right choices. Also, consider framework updates and files you modify in the engine folder.
If you look at the .htaccess file in the root directory of a Trongate app, it loads '/public /index.php' first:
This would be a better place to insert your vendor autoload, not 'bootstrap.php' as it will be overwritten on version changes when you update your app with the Desktop app or replace the engine manually from GitHub.
Also, I always look to load things (third-party libs etc...) in as needed. For instance, If I have an invoice module that outputs a PDF (not unlike the video DC has shared above) then I'll load it from the module and to make it modular, I'll move the third-party library to the assets directory of the module. This avoids it being loaded on each and every page load and only used as needed.
I haven't used PHP-DI so can't comment
Happy coding, and thanks for choosing Trongate!
Cheers,
Si
As DC has suggested, take a look through the video he posted on the subject of using Packagist with Trongate. It's quite simple to do and use.
For me, it's always about 'how it makes you feel' and 'if you feel good' then that usually is the correct way to do it, so don't let anyone tell you 'this is how you should do it' or 'if you're not doing it my way, you're doing it wrong'. I hate those tutorials or people who push their agenda on others.
But in saying that, it's always a good idea to have a look at how Trongate loads and in what order so you can make the right choices. Also, consider framework updates and files you modify in the engine folder.
If you look at the .htaccess file in the root directory of a Trongate app, it loads '/public /index.php' first:
This would be a better place to insert your vendor autoload, not 'bootstrap.php' as it will be overwritten on version changes when you update your app with the Desktop app or replace the engine manually from GitHub.
Also, I always look to load things (third-party libs etc...) in as needed. For instance, If I have an invoice module that outputs a PDF (not unlike the video DC has shared above) then I'll load it from the module and to make it modular, I'll move the third-party library to the assets directory of the module. This avoids it being loaded on each and every page load and only used as needed.
I haven't used PHP-DI so can't comment
Happy coding, and thanks for choosing Trongate!
Cheers,
Si
3 years ago
#4
I watched the instructional video.
After posting the question, I searched for information from popular frameworks, searching about PHP-DI.
My personal conclusion is: I did not do it right when changing the framework code, and my project scale was small, PHP-DI was not needed.
Thanks Dafa for the helpful advice. Thanks for greeting me in Vietnamese. Wish you everything is the best.
Except I got a little slow response at the Help-bar. This problem seems to have been resolved.
After posting the question, I searched for information from popular frameworks, searching about PHP-DI.
My personal conclusion is: I did not do it right when changing the framework code, and my project scale was small, PHP-DI was not needed.
Thanks Dafa for the helpful advice. Thanks for greeting me in Vietnamese. Wish you everything is the best.
Except I got a little slow response at the Help-bar. This problem seems to have been resolved.