Prat
Prat

Reputation: 519

How to include external PHP file in Magento?

How to include external PHP file in Magento? Can we include this file in event-observer model's Observer.php file? How can we execute external PHP file in Magento?

Upvotes: 0

Views: 2080

Answers (1)

Ben Lessani
Ben Lessani

Reputation: 2151

Including another class can easily be achieved by just making an extension for the classes used. Then just use standard Magento class loading techniques to access them:

Mage::getModel('mynamespace/mymodule')->myFunction()
Mage::helper('mymodulefrontname')->myFunction()

It would also be worth considering creating the MySQL connection through Zend/Varien itself. Here is a starter function:

protected function _initiateDbConnection()
{
        $configs = array('model' => 'mysql4', 'active' => '1', 'host' => 'localhost', 'username' => '', 'password' => '', 'dbname' => '', 'charset' => 'utf8');         
        return Mage::getSingleton('core/resource')->createConnection('mymodule_read', 'pdo_mysql', $configs);
} 

Which will give you an Zend DB instance that you can execute query() etc. on.

Upvotes: 1

Related Questions