Book Image

Magento 2 Development Cookbook

Book Image

Magento 2 Development Cookbook

Overview of this book

With the challenges of growing an online business, Magento 2 is an open source e-commerce platform with innumerable functionalities that gives you the freedom to make on-the-fly decisions. It allows you to customize multiple levels of security permissions and enhance the look and feel of your website, and thus gives you a personalized experience in promoting your business.
Table of Contents (13 chapters)
12
Index

Creating a controller


In your Magento root, create the following folders: We will add an extra page that we can use for several purposes.

Getting ready

We build further on the Packt_HelloWorld module that we created in the previous recipe. Ensure that you have this module in your Magento instance. Also, ensure that the full page cache is disabled when you are developing. You can disable this in the backend by navigating to System | Cache Management.

How to do it...

The following steps show how to add extra pages using controllers and controller actions:

  1. Create the following folders:

    • app/code/Packt/HelloWorld/etc/frontend

    • app/code/Packt/HelloWorld/Controller

    • app/code/Packt/HelloWorld/Controller/Index

  2. In the app/code/Packt/HelloWorld/etc/frontend folder, create a routes.xml file with the following content:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
        <router id="standard...