Question

I am working in Magento 1.9 . In some specific requirement i have to make a PHP file at Magento ROOT directory . Some API will hit that file and send some data to it . I have to save that data in DB in core_config_data . For this please see my code .

<?php class Response{
public function __construct() { 
    umask(0); require "app/Mage.php"; 
    require "app/code/core/Mage/Core/Model/Config.php"; 
    $this->getResponse();}function getResponse(){
Mage::getConfig()->saveConfig("notification_data",json_encode($_GET));}}new Response(); 

But it gave the error Fatal error: Uncaught Error: Call to a member function saveConfig() on null.

Any body please help to fix the issue .

Was it helpful?

Solution

Keeping a php script which allows access to the Magento instance in your root directory is a big security risk. With that said, if you still finds this has to be done in a wrong way, then please proceed.

You should need to create Magento application bootstrap environment in prior to your code. Add below code before your class:

<?php
//some settings
error_reporting(E_ALL | E_STRICT); 
define('MAGENTO_ROOT', getcwd()); 
$mageFilename = MAGENTO_ROOT . '/app/Mage.php'; 
require_once $mageFilename; 
Mage::setIsDeveloperMode(true); 
ini_set('display_errors', 1); 
umask(0);
//instantiate the app model
Mage::app(); 
// your dirty code goes here

OTHER TIPS

You missing Mage::app()

Below is the simple code to save/update configuration from your root directory PHP file.

<?php
require_once('app/Mage.php');
Mage::app();

Mage::getConfig()->saveConfig("notification_data",'PASS_YOUR_JSON_DATA HERE');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top