I'd like to setup Magento so that if I make a request with an URL such as:
http://mymagento.com/api/storeconfig (actual url format not important)
would return json with the data requested. How can I achieve this? Here's how I'm retrieving the data:
public function getStoreSettings()
{
//this successfully retrieves the value of my custom settings property
$my_property= Mage::getStoreConfig('my_module/my_settings/my_property', 'default');
$data = array('my_property'=>$my_property);
$json = Mage::helper('core')->jsonEncode($data);
//return json here
}
Where would the right place to add this code? How can I map an URL to call this function and return the response as json? I appreciate if anyone could point me in the right direction!
Best Answer
After lots of playing around with Magento, trying to figure out all the magic going on, I found a solution to my problem, and am adding a solution for those who may come across the same task.
1 - Go to your app/etc/modules/YourPackage_YourModule.xml This is what I have:
this will create a route for http://yourmagento.com/yourmodule/yourcontroller/youraction
2- Go to app/code/community/YourPackage/YourModule/controllers/ Create your YourController.php. This is mine:
There's a lot of magic going on with the naming conventions, for a more in-depth walk-through, check out Magento for Developers: Part 3 - Magento Controller Dispatch