2017 © Pedro PelĂĄez
 

magento2-module magento2-virtual-controllers

A module which enables developers to create virtual controllers in Magento 2

image

renttek/magento2-virtual-controllers

A module which enables developers to create virtual controllers in Magento 2

  • Thursday, June 28, 2018
  • by renttek
  • Repository
  • 2 Watchers
  • 22 Stars
  • 186 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 343 % Grown

The README.md

Renttek_VirtualControllers

Enables creating of routes with "virtual controllers", (*1)

Build Status Latest Stable Version License, (*2)

What is a virtual controllers? A virtual controller is a path + an optional layout handle which will be set. With that it is possible to create custom routes where you can place custom blocks to your wishes. (In Magento 2 this is currently only possible by creating a route.xml & a dummy controller action, which returns a \Magento\Framework\View\Result\Page), (*3)

Comparison

Here is a short comparison of the minimal required code to create a custom route (example/page/view) in Magento 2 (given there is already a module My_Module), (*4)

Vanilla Magento 2

/etc/frontend/routes.xml, (*5)

<?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">
        <route id="example" frontName="example">
            <module name="My_Module"/>
        </route>
    </router>
</config>

/Controllers/Page/View.php, (*6)

resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {
        return $this->resultPageFactory->create();
    }
}
```

### With this Module

/etc/virtual_controllers.xml
```xml

<controllers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Renttek_VirtualControllers:etc/virtual_controllers.xsd">
    <controller path="example/page/view" />
</controllers>

Features

Handles

Besides the much simpler creation of custom routes, every route will get a few layout handles set: * "default" * "virtual_controller" * The given path, but all characters except [a-z_] are replaced by underscores. (example/page/view => example_page_view), (*7)

The generated handle can also be set manually in the xml configuration like this:, (*8)

/etc/virtual_controllers.xml, (*9)

<?xml version="1.0"?>
<controllers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Renttek_VirtualControllers:etc/virtual_controllers.xsd">
    <controller path="example/page/view" handle="my_custom" />
</controllers>

Routes can also be disabled by setting disabled=true in the configuration:, (*10)

<?xml version="1.0"?>
<controllers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Renttek_VirtualControllers:etc/virtual_controllers.xsd">
    <controller path="example/page/view" disabled="true" />
</controllers>

Forwards

Another feature is the possibility of creating forwards without creating a controller. Forwards are needed if you want to display another URL for a page. (e.g. 'my/shoppingcart' => 'checkout/cart'), (*11)

<?xml version="1.0"?>
<controllers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Renttek_VirtualControllers:etc/virtual_controllers.xsd">

    <forward path="my/shoppingcart"
             module="checkout"
             controller="cart"
             action="index"/>
</controllers>

In V1 the attributes controller and action defaulted to 'index' if not specified. In V2 this is not the case!, (*12)

Forwards are only URLs/path that CAN be called. It does not extend/manipulate url generation in any way., (*13)


All routes are merged by the path attribute, so it is possible to disable routes from other modules., (*14)

The Versions

28/06 2018

dev-master

9999999-dev

A module which enables developers to create virtual controllers in Magento 2

  Sources   Download

MIT

The Requires

  • php ~7.1
  • magento/framework ~101.0.0

 

The Development Requires

by Julian Nuß

28/06 2018

1.1.1

1.1.1.0

A module which enables developers to create virtual controllers in Magento 2

  Sources   Download

MIT

The Requires

  • php ~7.1
  • magento/framework ~101.0.0

 

The Development Requires

by Julian Nuß

28/06 2018

1.1.0

1.1.0.0

A module which enables developers to create virtual controllers in Magento 2

  Sources   Download

MIT

The Requires

  • php ~7.1
  • magento/framework ~101.0.0

 

The Development Requires

by Julian Nuß

14/05 2018

1.0.1

1.0.1.0

A module which enables developers to create virtual controllers in Magento 2

  Sources   Download

MIT

The Requires

  • php ~7.1
  • magento/framework ~101.0.0

 

The Development Requires

by Julian Nuß

13/05 2018

1.0.0

1.0.0.0

A module which enables developers to create virtual controllers in Magento 2

  Sources   Download

MIT

The Requires

  • php ~7.1
  • magento/framework ~101.0.0

 

The Development Requires

by Julian Nuß