TreeLayoutStack
⚠️ This module is for Zend Framework 2, it is deprecated ⚠️, (*1)
, (*2)
NOTE : If you want to contribute don't hesitate, I'll review any PR., (*3)
Introduction
TreeLayoutStack is module for ZF2 allowing the creation of tree layout, (*4)
Requirements
Installation
Main Setup
By cloning project
- Clone this project into your
./vendor/
directory.
With composer
-
Add this project in your composer.json:, (*5)
"require": {
"neilime/zf2-tree-layout-stack": "dev-master"
}
-
Now tell composer to download TreeLayoutStack by running the command:, (*6)
$ php composer.phar update
Post installation
-
Enabling it in your application.config.php
file., (*7)
<?php
return array(
'modules' => array(
// ...
'TreeLayoutStack',
),
// ...
);
How to use TreeLayoutStack
Simple configuration example
This example shows how to define a simple tree layout stack with header and footer parts, (*8)
-
After installing skeleton application, install TreeLayoutStack as explained above., (*9)
-
Edit the application module configuration file module/Application/config/module.config.php
, adding the configuration fragment below:, (*10)
```php
<?php
return array(
//...
'tree_layout_stack' => array(
'layout_tree' => array(
'default' => array(
'template' => 'layout/layout',
'children' => array(
'header' => 'header/header',
'footer' => 'footer/footer'
)
)
)
),
//...
'view_manager' => array(
'template_map' => array(
//...
'layout/layout' => DIR . '/../view/layout/layout.phtml',
'header/logged' => DIR . '/../view/layout/header.phtml',
'footer/footer' => DIR . '/../view/layout/footer.phtml'
//...
)
)
//...
);, (*11)
-
Edit layout file module/Application/view/layout/layout.phtml
, adding header and footer where you want to display them, (*12)
//...
echo $this->header; //Display header part
//...
//...
echo $this->layout()->content; //Display content part
//...
//...
echo $this->layout()->footer; //Display footer part
//...
-
Create header and footer view files
module/Application/view/layout/header.phtml
module/Application/view/layout/footer.phtml
, (*13)
-
Save & Resfresh., (*14)
Configuration
-
TreeLayoutStack :
- array
layout_tree
: Define the layout tree, you can define differents tree layout stack, depends on module name, the default
configuration is used if no template is defined for current module
- Module layout tree map (
layout_tree
entry) :
- string|array|callable template : define the template name
- array children : (optionnal) define children of the template, the configuration is the same as the
layout_tree
entry or template
Complexe exemple
This example shows all the configuration options available, it assume that template_map
is properly defined in view_manager
configuration, (*15)
```php
<?php
return array(
//...
'tree_layout_stack' => array(
'layout_tree' => array(
'default' => array(
'template' => 'layout/layout',
'children' => array(
'header' => function(\Zend\Mvc\MvcEvent $oEvent){
return $oEvent->getViewModel()->isLoggedUser?'header/logged':'header/unlogged' // Current MVC event is passed as argument to the callable template
},
'footer' => array(
'template' => 'footer/footer',
'children' => array(
'social' => 'footer/social',
'sitemap' => array('SampleClass','SampleFunction') //Sample callback
)
)
)
)
)
),
//...
);
```