2017 © Pedro Pelรกez
 

symfony-bundle simple-hmvc-bundle

Symfony bundle to support the HMVC design pattern

image

beyerz/simple-hmvc-bundle

Symfony bundle to support the HMVC design pattern

  • Tuesday, July 3, 2018
  • by beyerz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 977 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 25 % Grown

The README.md

SimpleHMVCBundle

Simple HMVC Bundle for Symfony2, (*1)

The HMVC design pattern, came about when trying resolve the problem of embedding widgets into pages. HMVC allows us to cleanly separate Controller, Model and View logic's, enabling us to create easier to work with and clearly encompassed code., (*2)

Symfony2 does provide us with tools that allow us to "load" routes within our controllers and our views, but the process, behind the scenes, is more complex than I like., (*3)

For info on embedding using the symfony provided options see: http://symfony.com/doc/2.8/book/templating.html#templating-embedding-controller, (*4)

HMVC (Hierarchical model-view-controller) symfony bundle enables you to "Widgetize" or as used in this bundle "Elementize" your controllers. Architecturally this allows you to recursively include the same element one or many times across multiple pages without having to rebuild or restate the model logic., (*5)

Installation

composer require beyerz/simple-hmvc-bundle

Application Kernel

Add SimpleHMVC to the registerBundles() method of your application kernel:, (*6)

public function registerBundles()
{
    return array(
        new Beyerz\SimpleHMVCBundle\BeyerzSimpleHMVCBundle(),
    );
}

Usage

Pages and Elements can be created by hand or generated using the provided commands. If you choose to create them manually or need to update manually, please consider the expected file structure, (*7)

Creating Pages

Using the command, (*8)

php app/console hmvc:page

For additional options or help, (*9)

php app/console hmvc:page --help

This command will generate a controller with one or many actions according to your specification. For every controller action the following classes will be created, {action}Model, {action}Context, {action}Input and a view in snake case format., (*10)

The creation of a page with results in the following directory structure The Controller name used here is: BeyerzTestingBundle:GitExample, (*11)

โ”œโ”€โ”€ Context
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ”œโ”€โ”€ FirstExampleContext.php
โ”‚ย ย          โ””โ”€โ”€ SecondExampleContext.php
โ”œโ”€โ”€ Controller
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExampleController.php
โ”œโ”€โ”€ Input
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ”œโ”€โ”€ FirstExampleInput.php
โ”‚ย ย          โ””โ”€โ”€ SecondExampleInput.php
โ”œโ”€โ”€ Model
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ”œโ”€โ”€ FirstExampleModel.php
โ”‚ย ย          โ””โ”€โ”€ SecondExampleModel.php
โ”œโ”€โ”€ Resources
โ”‚ย ย  โ”œโ”€โ”€ config
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ routing.yml
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ services.yml
โ”‚ย ย  โ””โ”€โ”€ views
โ”‚ย ย      โ””โ”€โ”€ Page
โ”‚ย ย          โ””โ”€โ”€ GitExample
โ”‚ย ย              โ”œโ”€โ”€ first_example.html.twig
โ”‚ย ย              โ””โ”€โ”€ second_example.html.twig
โ””โ”€โ”€ Tests
    โ””โ”€โ”€ Controller
        โ””โ”€โ”€ Page
            โ””โ”€โ”€ GitExampleControllerTest.php

You can also create controllers under different directories by specifying the path during the creation. A simple sub-controller would generate this file structure The Controller name used here is: BeyerzTestingBundle:GitExample/SubExample, (*12)

โ”œโ”€โ”€ Context
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubExample
โ”‚ย ย              โ”œโ”€โ”€ FirstSubExampleContext.php
โ”‚ย ย              โ””โ”€โ”€ SecondSubExampleContext.php
โ”œโ”€โ”€ Controller
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubExampleController.php
โ”œโ”€โ”€ Input
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubExample
โ”‚ย ย              โ”œโ”€โ”€ FirstSubExampleInput.php
โ”‚ย ย              โ””โ”€โ”€ SecondSubExampleInput.php
โ”œโ”€โ”€ Model
โ”‚ย ย  โ””โ”€โ”€ Page
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubExample
โ”‚ย ย              โ”œโ”€โ”€ FirstSubExampleModel.php
โ”‚ย ย              โ””โ”€โ”€ SecondSubExampleModel.php
โ”œโ”€โ”€ Resources
โ”‚ย ย  โ”œโ”€โ”€ config
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ routing.yml
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ services.yml
โ”‚ย ย  โ””โ”€โ”€ views
โ”‚ย ย      โ””โ”€โ”€ Page
โ”‚ย ย          โ””โ”€โ”€ GitExample
โ”‚ย ย              โ””โ”€โ”€ SubExample
โ”‚ย ย                  โ”œโ”€โ”€ first_sub_example.html.twig
โ”‚ย ย                  โ””โ”€โ”€ second_sub_example.html.twig
โ””โ”€โ”€ Tests
    โ””โ”€โ”€ Controller
        โ””โ”€โ”€ Page
            โ””โ”€โ”€ GitExample
                โ””โ”€โ”€ SubExampleControllerTest.php

Creating Elements

Elements are very similar to pages, except that no controller is generated for elements., (*13)

Using the command, (*14)

php app/console hmvc:element

For additional options or help, (*15)

php app/console hmvc:element --help

This command will generate the following classes, {element}Model, {element}Context, {element}Input and a view in snake case format., (*16)

The creation of an element results in the following directory structure The Element name used here is: BeyerzTestingBundle:GitElement, (*17)

โ”œโ”€โ”€ Context
โ”‚ย ย  โ””โ”€โ”€ Element
โ”‚ย ย      โ””โ”€โ”€ GitElementContext.php
โ”œโ”€โ”€ Controller
โ”œโ”€โ”€ DependencyInjection
โ”‚ย ย  โ”œโ”€โ”€ BeyerzTestingExtension.php
โ”‚ย ย  โ””โ”€โ”€ Configuration.php
โ”œโ”€โ”€ Input
โ”‚ย ย  โ””โ”€โ”€ Element
โ”‚ย ย      โ””โ”€โ”€ GitElementInput.php
โ”œโ”€โ”€ Model
โ”‚ย ย  โ””โ”€โ”€ Element
โ”‚ย ย      โ””โ”€โ”€ GitElementModel.php
โ”œโ”€โ”€ Resources
โ”‚ย ย  โ”œโ”€โ”€ config
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ routing.yml
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ services.yml
โ”‚ย ย  โ””โ”€โ”€ views
โ”‚ย ย      โ””โ”€โ”€ Element
โ”‚ย ย      ย  ย  โ””โ”€โ”€ git_element.html.twig
โ””โ”€โ”€ Tests

You can also create elements under different directories by specifying the path during the creation. A simple sub-element would generate this file structure The element name used here is: BeyerzTestingBundle:GitExample/SubElement, (*18)

โ”œโ”€โ”€ Context
โ”‚ย ย  โ””โ”€โ”€ Element
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubElementContext.php
โ”œโ”€โ”€ Controller
โ”œโ”€โ”€ DependencyInjection
โ”‚ย ย  โ”œโ”€โ”€ BeyerzTestingExtension.php
โ”‚ย ย  โ””โ”€โ”€ Configuration.php
โ”œโ”€โ”€ Input
โ”‚ย ย  โ””โ”€โ”€ Element
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubElementInput.php
โ”œโ”€โ”€ Model
โ”‚ย ย  โ””โ”€โ”€ Element
โ”‚ย ย      โ””โ”€โ”€ GitExample
โ”‚ย ย          โ””โ”€โ”€ SubElementModel.php
โ”œโ”€โ”€ Resources
โ”‚ย ย  โ”œโ”€โ”€ config
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ routing.yml
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ services.yml
โ”‚ย ย  โ””โ”€โ”€ views
โ”‚ย ย      โ””โ”€โ”€ Element
โ”‚ย ย       ย ย  โ””โ”€โ”€ GitExample
โ”‚ย ย       ย ย      โ””โ”€โ”€ sub_element.html.twig
โ””โ”€โ”€ Tests

How it works

Some useful articles

  • http://www.javaworld.com/article/2076128/design-patterns/hmvc--the-layered-pattern-for-developing-strong-client-tiers.html

The Versions

03/07 2018

dev-master

9999999-dev

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

03/07 2018

2.0.3

2.0.3.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

08/02 2018

2.0.2

2.0.2.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

18/09 2017

2.0.1

2.0.1.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

19/07 2017

2.0.0

2.0.0.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

15/03 2017

1.0.2

1.0.2.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

15/03 2017

1.0.1

1.0.1.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller

14/03 2017

1.0.0

1.0.0.0

Symfony bundle to support the HMVC design pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 symfony hmvc hierarchical model view controller