Magento 2: Return JSON, XML, HTML & Raw Text Data Response from Controller

This article shows how you can return JSON data, XML data, HTML data, or Raw Text data from any Controller class in Magento 2. Generally, in the Magento2 controller’s execute() function, we see the redirect or forwarding call which redirects to the specified URL page. However, we might sometime need to return the JSON format … Read more

Magento: Add a custom block inside another block

You can add custom blocks inside already existing block through your custom layout xml file. You don’t need to change the template (phtml) code. Suppose, you want to add a block inside product view page. To do so, you can write the following xml code in your custom module’s layout file. In the below code, … Read more

Magento: Read config XML nodes

Here, I will be showing you how you can read XML nodes from config.xml file of your module. It’s through the Magento way with Mage::getConfig()->getNode() function. :) Here is the XML code of my config.xml file. I will be reading the nodes of this XML file. <default> <catalog> <mypage> <name>myname</name> <age>100</age> <address_one>earth</address_one> </mypage> </catalog> </default> … Read more

Magento: Read Write XML

I will be using Varien_Simplexml_Element class to read write xml nodes. The path to this class file is lib/Varien/Simplexml/Element.php Here is a sample XML file which I am going to read through Magento code. I will also be adding an XML node to the following XML data. <?xml version="1.0"?> <config> <modules> <MyNamespace_MyModule> <version>0.1.0</version> </MyNamespace_MyModule> </modules> … Read more

Magento: Access denied in admin of custom module

I was building a custom module in Magento. I had created a system.xml file for storing configuration data from admin. From the below system.xml file, you can see that I have created a section named ‘My Module Name‘ which can be accessed from Admin –> System –> Configuration. In the file below, I have just … Read more

PHP : Read Write XML with DOMDocument

In this article, I will be showing you how to create and read xml document with php’s DOMDocument. The DOM extension allows you to operate on XML documents through the DOM API with PHP 5. Below is the code to create XML file. I have named the output file ‘example.xml’. For better understanding, I have … Read more

PHP : Read Write XML with SimpleXML

In this article, I will be showing you how to create and read xml document with php’s SimpleXML extension. The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators. Below is the code to create XML file. … Read more