<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">

Magento 2: Module Code Generation with Pestle

Makarand Uparwat Nov 20, 2018

Magento 2.0 Pestle

What is Pestle?

The Pestle is a new PHP (5.6+) framework for creating and organizing PHP programs into Python like libraries of functions. Currently, Pestle has commands for generating a new module, a new route, a new view/block/layout for that route and many more.

Installing on Linux

System requirements
  • PHP 5.6+
Download the latest build using following curl

  • $ curl -LO http://pestle.pulsestorm.net/pestle.phar
  • After download give it an exccute permission
    $ sudo chmod +x pestle.phar
  • Now move it to /usr/local/bin/
    $ sudo mv pestle.phar /usr/local/bin/pestle.phar
  • Now use command $ pestle.phar version. You will able to see the current installed version of Pestle.
    pestle Ver 1.4.3
After successful installation, you can go on generating a new module using command line.

Creating a Basic Module

If you’ve worked on a custom module, you know creating a basic Magento module is straightforward, but it involves many different files. Pestle can handle that boring and repetitive work of creating those files for you.

The first step of a custom module is to create module.xml and registration.php file. To create these file run the following command.

$ pestle.phar generate_module

Then enable it using the following command

$ php bin/magento module:enable Ezest_HelloWorld
$ php bin/magento setup:upgrade

Adding the Route & Index Action

The next step of creating a Magento module is adding a route.
$ pestle.phar generate_route

Adding a Frontend View Files
Now we need to add Magento’s default view files, like XML file, phtml template, and default block/view class.

$ pestle.phar generate_view

After running the above command, clear your cache and reload the page. You should see your view’s content.

Simple Yet Powerful Commands

It is possible to specify any input as a command argument. What this means is that you could recreate the above module with just three simple commands.
$ pestle.phar generate_module Ezest HelloWorld 0.0.1

$ pestle.phar generate_route Ezest_HelloWorld frontend hello_world

$ pestle.phar generate_view Ezest_HelloWorld frontend hello_world_index_index Main content.phtml

These above commands will automatically create the required files and folder structure, as shown in below image.
Hope this helps you to reduce the manual work of creating files of your custom module using Pestle.

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.