neilime / zf2-tree-layout-stack
TreeLayoutStack is a module for ZF2 allowing the creation of tree layout
Installs: 442
Dependents: 2
Suggesters: 1
Security: 0
Stars: 5
Watchers: 2
Forks: 4
Open Issues: 1
Language:HTML
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.*
This package is auto-updated.
Last update: 2020-08-09 19:08:35 UTC
README
⚠️ This module is for Zend Framework 2, it is deprecated ⚠️
NOTE : If you want to contribute don't hesitate, I'll review any PR.
Introduction
TreeLayoutStack is module for ZF2 allowing the creation of tree layout
Requirements
- Zend Framework 2 (latest master)
Installation
Main Setup
By cloning project
- Clone this project into your
./vendor/
directory.
With composer
-
Add this project in your composer.json:
"require": { "neilime/zf2-tree-layout-stack": "dev-master" }
-
Now tell composer to download TreeLayoutStack by running the command:
$ php composer.phar update
Post installation
-
Enabling it in your
application.config.php
file.<?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
-
After installing skeleton application, install TreeLayoutStack as explained above.
-
Edit the application module configuration file
module/Application/config/module.config.php
, adding the configuration fragment below:<?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' //... ) ) //... );
-
Edit layout file
module/Application/view/layout/layout.phtml
, adding header and footer where you want to display them//... 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
-
Save & Resfresh.
Configuration
- TreeLayoutStack :
- array
layout_tree
: Define the layout tree, you can define differents tree layout stack, depends on module name, thedefault
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 ortemplate
Complexe exemple
This example shows all the configuration options available, it assume that template_map
is properly defined in view_manager
configuration
```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
)
)
)
)
)
),
//...
);
```