How to include external php file in magento module?

I am creating a magento module and I need to use some 3rdParty classes "ThiredPartyClassA" and "ThiredPartyClassB" which are in the external file "thirdPartyCode.php".

Where to place the thirdPartyCode.php file? and how do I call (require_once) if I can use it in one of my action handlers?

Thank you Eyal

+4
source share
3 answers

I finished creating the lib directory in my main module directory. It seemed "the best of both worlds."

$ExternalLibPath=Mage::getModuleDir('', 'My_Module') . DS . 'lib' . DS .'EXTERNALLIB.php'; require_once ($ExternalLibPath); 
+14
source

You can require files in PHP in the same way as without Magento, so you can use require_once if necessary. If you want your code to be cleaner, you can put it in the /lib folder in Magento, as it is a system library. I'm not sure if this is included in the default inclusion path, so you may have to bother with the requirement.

For cleanliness, you can also create a wrapper around this code and use Magento models / helpers to manage them.

Hope this helps!

Thanks Joe

+4
source

Like any PHP script, you can include files wherever you are.

However, you can use the built-in autoloader in Magento. I'm sure Magento uses Zend for autoload. (In any case, it is available to you)

Zend, unlike Magento, has good documentation. Take a look here http://framework.zend.com/manual/en/zend.loader.autoloader.html

+1
source

Source: https://habr.com/ru/post/1332962/


All Articles