Facade use cases

Edit on GitHub

This document describes the use cases of a facade.

The facade usage from a controller or plugin

In Zed’s Communication layer, the facade of the same module is available with the getFacade() method from all controllers and plugins. image

Typical usage from a controller is as follows. The controller retrieves data from a submitted form and calls a method of a facade to save it:

<?php
namespace Pyz\Zed\Glossary\Communication\Controller;

class FormController extends AbstractController
{
    public function translationAction()
    {
        // ...
        if ($form->isValid()) {
            $translation = new TranslationTransfer();
            $translation->fromArray($form->getRequestData());
            $this->getFacade()->saveTranslation($translation);
        }
        // ...
    }

The facade usage from another module

To connect modules you can provide the facade to another module. To do so, you need to use the dependency provider mechanism.