├── .gitignore
├── LICENSE
├── Module.php
├── README.md
├── composer.json
├── config
└── zfcadmin.global.php
├── docs
├── 1.Introduction.md
├── 2.Routes.md
├── 3.Navigation.md
├── 4.Authorization.md
└── 5.ViewLayout.md
├── src
├── ConfigProvider.php
├── Controller
│ └── AdminController.php
├── Module.php
└── Navigation
│ └── Service
│ └── AdminNavigationFactory.php
└── view
├── layout
└── admin.phtml
└── zfc-admin
└── admin
└── index.phtml
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | composer.lock
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, ZF-Commons Contributors
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | Neither the name of the ZF-Commons nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/Module.php:
--------------------------------------------------------------------------------
1 |
37 | * @copyright 2012 Jurian Sluiman.
38 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
39 | * @link http://zf-commons.github.com
40 | */
41 |
42 | include_once __DIR__ . '/src/Module.php';
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ZfcAdmin Module for Zend Framework
2 | Created by [Jurian Sluiman](http://juriansluiman.nl) and [Martin Shwalbe](https://github.com/Hounddog).
3 |
4 | ## Introduction
5 | ZfcAdmin is a minimal admin interface for generic administrative purposes. It is a common screen with navigation that hides behind authentication and authorization.
6 |
7 | ## Installation
8 | ZfcAdmin is enabled to be installed via composer. Load `zf-commons/zfc-admin` in your `composer.json` file. You can specify its version (currently only 0.1.0 is recommended) or use `dev-master` to load the latest version from master. Enable ZfcAdmin in your `application.config.php` configuration file.
9 |
10 | If you do not want to use composer, clone this project (either as a git submodule or not) into `./vendor/` directory.
11 |
12 | ## Usage
13 | ZfcAdmin allows you to create routes under a single parent "admin" route. You can also use it to enable navigation in your admin layout. Furthermore integration of [BjyAuthorize](https://github.com/bjyoungblood/BjyAuthorize) and [ZfcRbac](https://github.com/ZF-Commons/zfc-rbac) is provided.
14 |
15 | The complete configuration is flexible, so you can update the zfcadmin parent route, its children, the navigation and all default provided view scripts. Read more in the [documentation](docs/1.Introduction.md) about usage and customization of ZfcAdmin.
16 |
17 | ## Development
18 | ZfcAdmin is currently under development. The authors feel ZfcAdmin is stable enough for production versions and you can always fix your ZfcAdmin version to a specific tag. Feel free to report bugs in the [issue tracker](https://github.com/ZF-Commons/ZfcAdmin/issues) or come by on IRC at the Freenode channel `#zftalk`.
19 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "zf-commons/zfc-admin",
3 | "description": "A generic Admin module for ZF2.",
4 | "license": "BSD-3-Clause",
5 | "type": "library",
6 | "keywords": [
7 | "zf2"
8 | ],
9 | "homepage": "https://github.com/juriansluiman/ZfcAdmin",
10 | "authors": [
11 | {
12 | "name": "Jurian Sluiman ",
13 | "email": "jurian@juriansluiman.nl",
14 | "homepage": "http://juriansluiman.nl/en/"
15 | },
16 | {
17 | "name": "Martin Shwalbe",
18 | "email": "martin.shwalbe@gmail.com"
19 | }
20 | ],
21 | "require": {
22 | "php": "^5.5 || ^7.0",
23 | "zendframework/zend-modulemanager": "^2.5",
24 | "zendframework/zend-loader": "^2.5",
25 | "zendframework/zend-eventmanager": "^2.5 || ^3.0",
26 | "zendframework/zend-mvc": "^2.5 || ^3.0",
27 | "zendframework/zend-navigation": "^2.5"
28 | },
29 | "suggest": {
30 | "bjyoungblood/bjy-authorize": "Access control to protect ZfcAdmin against unauthorized users"
31 | },
32 | "autoload": {
33 | "psr-4": {
34 | "ZfcAdmin\\": "src/"
35 | }
36 | },
37 | "extra": {
38 | "zf": {
39 | "component": "ZfcAdmin",
40 | "config-provider": [
41 | "ZfcAdmin\\ConfigProvider"
42 | ]
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/config/zfcadmin.global.php:
--------------------------------------------------------------------------------
1 | true,
20 |
21 | /**
22 | * Layout template for ZfcAdmin
23 | *
24 | * When use_admin_layout is set to true, this value will be used as template
25 | * name for the admin layout. Default is 'layout/admin'
26 | *
27 | * Accepted is a string that resolves to a view script
28 | */
29 | //'admin_layout_template' => 'layout/admin',
30 |
31 | /**
32 | * End of ZfcAdmin configuration
33 | */
34 |
35 | ];
36 |
37 | /**
38 | * You do not need to edit below this line
39 | */
40 | return [
41 | 'zfcadmin' => $settings,
42 |
43 | /**
44 | * Default BjyAuthorize configuration for ACL
45 | */
46 | 'bjyauthorize' => [
47 | 'guards' => [
48 | 'BjyAuthorize\Guard\Route' => [
49 | ['route' => 'zfcadmin', 'roles' => ['admin']],
50 | ],
51 | ],
52 | ],
53 |
54 | /**
55 | * Default ZfcRbac configuration for RBAC
56 | */
57 | 'zfcrbac' => [
58 | 'firewall_route' => true,
59 | 'firewalls' => [
60 | 'ZfcRbac\Firewall\Route' => [
61 | 'zfcadmin' => ['route' => '^zfcadmin/*', 'roles' => 'admin'],
62 | ],
63 | ],
64 | ],
65 | ];
66 |
--------------------------------------------------------------------------------
/docs/1.Introduction.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 | ZfcAdmin is a low-level module that helps Zend Framework 2 developers to create an admin interface. The module allows to have a uniform layout, navigation structure and routing scheme. You can create controllers routed as a child of ZfcAdmin, so you can easily change the (root) url, access control and other properties. The navigation is also flexible, to allow you having a structure built of pages in the admin interface with menus, breadcrumbs and other links.
3 |
4 | Every part of ZfcAdmin is customizable. In the pages listed below futher configuration options are explained. This documentation consists of the following pages:
5 |
6 | 1. [Introduction](1.Introduction.md)
7 | 2. [Routes](2.Routes.md)
8 | 3. [Navigation](3.Navigation.md)
9 | 4. [Authorization](4.Authorization.md)
10 | 5. [Views & Layout](5.ViewLayout.md)
--------------------------------------------------------------------------------
/docs/2.Routes.md:
--------------------------------------------------------------------------------
1 | # Routes
2 | ZfcAdmin enables a single route named `zfcadmin`, which is a literal route and standard using the url `/admin`. You can create child routes under `zfcadmin` so you enable urls like `/admin/foo` or `/admin/bar/baz`.
3 |
4 | ## Add child route
5 | To register a route as child route, the following example takes the option you name that route `foo`. The complete path should look like `/admin/foo`, so `foo` is a literal route with the route value `/foo`. Say you want this route to connect to your `MyModule\Controller\MyController` controller and the `index` action, create this config in your `module.config.php`:
6 |
7 |
8 | 'router' => array(
9 | 'routes' => array(
10 | 'zfcadmin' => array(
11 | 'child_routes' => array(
12 | 'foo' => array(
13 | 'type' => 'literal',
14 | 'options' => array(
15 | 'route' => '/foo',
16 | 'defaults' => array(
17 | 'controller' => 'MyModule\Controller\MyController',
18 | 'action' => 'index',
19 | ),
20 | ),
21 | ),
22 | ),
23 | ),
24 | ),
25 | ),
26 |
27 | ## Change the `/admin` url
28 | If you want your admin interface at `/backend` or something else, you must override the value of the route. In the following config, the `/admin` route value is replaced with `/backend`. Make sure this is enabled in a config where the module is registered *later* than ZfcAdmin (otherwise, the config will not overwrite ZfcAdmin's configuration):
29 |
30 | 'router' => array(
31 | 'routes' => array(
32 | 'zfcadmin' => array(
33 | 'options' => array(
34 | 'route' => '/backend',
35 | ),
36 | ),
37 | ),
38 |
39 | ## Change the controller behind `/admin`
40 | By default, the `/admin` url links to the `ZfcAdmin\Controller\AdminController` controller. It's an empty action and a simple view script is rendered. If you want, for example, create a dashboard on the admin index page, you probably need to point the route to another controller. In the following config, the `zfcadmin` route's controller is replaced with `MyModule/Controller/AdminController` and the action is set to `dashboard`. Make sure this is enabled in a config where the module is registered *later* than ZfcAdmin (otherwise, the config will not overwrite ZfcAdmin's configuration):
41 |
42 | 'router' => array(
43 | 'routes' => array(
44 | 'zfcadmin' => array(
45 | 'options' => array(
46 | 'defaults' => array(
47 | 'controller' => 'MyModule/Controller/AdminController',
48 | 'action' => 'dashboard',
49 | ),
50 | ),
51 | ),
52 | ),
53 | ),
54 |
55 | ## Link to documentation pages
56 |
57 | 1. [Introduction](1.Introduction.md)
58 | 2. [Routes](2.Routes.md)
59 | 3. [Navigation](3.Navigation.md)
60 | 4. [Authorization](4.Authorization.md)
61 | 5. [Views & Layout](5.ViewLayout.md)
--------------------------------------------------------------------------------
/docs/3.Navigation.md:
--------------------------------------------------------------------------------
1 | # Navigation
2 | ZfcAdmin allows a dedicated navigation structure for the admin interface. By default, ZfcAdmin initiates a [Twitter Bootstrap](http://twitter.github.com/bootstrap) layout with on top the main admin navigation. These admin buttons are customizable.
3 |
4 | ## Add a page
5 | The admin structure requires at least a `label` for the navigation element and a `route` or `url` parameter for the link to be created. The `route` will use the `url()` view helper to construct a link. It is recommended to use [routes](2.Routes.md) in your child pages of ZfcAdmin and therefore it is straightforward to use the `route` parameter in the navigation configuration.
6 |
7 | In the following example, there is a navigation element called "My Module" and points to `zfcadmin/foo/bar` as a route. This page is configured as follows:
8 |
9 | 'navigation' => array(
10 | 'admin' => array(
11 | 'my-module' => array(
12 | 'label' => 'My Module',
13 | 'route' => 'zfcadmin/foo/bar',
14 | ),
15 | ),
16 | ),
17 |
18 | The navigation in ZfcAdmin uses `Zend\Navigation` and more information about the configuration of this component is located in the [Zend Framework 2](http://framework.zend.com/manual/2.0/en/modules/zend.navigation.quick-start.html) reference guide.
19 |
20 | ## Link to documentation pages
21 |
22 | 1. [Introduction](1.Introduction.md)
23 | 2. [Routes](2.Routes.md)
24 | 3. [Navigation](3.Navigation.md)
25 | 4. [Authorization](4.Authorization.md)
26 | 5. [Views & Layout](5.ViewLayout.md)
--------------------------------------------------------------------------------
/docs/4.Authorization.md:
--------------------------------------------------------------------------------
1 | # Authorization
2 | ZfcAdmin allows authorization via [BjyAuthorize](https://github.com/bjyoungblood/BjyAuthorize) or [ZfcRbac](https://github.com/ZF-Commons/ZfcRbac). Configuration for both modules is provided to easily configure ZfcAdmin. Authorization enables you to restrict access to `/admin` and every other page under ZfcAdmin.
3 |
4 | ## BjyAuthorize authorization
5 | BjyAuthorize works with `Zend\Permission\Acl` as access restriction component. The BjyAuthorize module combines `Zend\Permission\Acl` with the standard user module [ZfcUser](https://github.com/ZF-Commons/ZfcUser). To enable access restriction with BjyAuthorize, install the module and enable it in your `application.config.php`.
6 |
7 | Furthermore, ZfcAdmin has a `zfcadmin.global.php` file in the [config](../config/) directory. Copy this file over to your `config/autoload` directory. It directly provides BjyAuthorize configuration to restrict access to users for the `/admin` route. Only users in the "admin" group are allowed to access ZfcAdmin's pages.
8 |
9 | Instructions for further configuration of BjyAuthorize are provided in the [repository of BjyAuthorize](https://github.com/bjyoungblood/BjyAuthorize).
10 |
11 | ## ZfcRbac authorization
12 | ZfcRbac works with `Zend\Permission\Rbac` as access restriction component. The ZfcRbac module combines `Zend\Permission\Rbac` with the standard user module [ZfcUser](https://github.com/ZF-Commons/ZfcUser). To enable access restriction with ZfcRbac, install the module and enable it in your `application.config.php`.
13 |
14 | Furthermore, ZfcAdmin has a `zfcadmin.global.php` file in the [config](../config/) directory. Copy this file over to your `config/autoload` directory. It directly provides ZfcRbac configuration to restrict access to users for the `/admin` route. Only users in the "admin" group are allowed to access ZfcAdmin's pages.
15 |
16 | Instructions for further configuration of ZfcRbac are provided in the [repository of ZfcRbac](https://github.com/ZF-Commons/ZfcRbac).
17 |
18 | ## Link to documentation pages
19 |
20 | 1. [Introduction](1.Introduction.md)
21 | 2. [Routes](2.Routes.md)
22 | 3. [Navigation](3.Navigation.md)
23 | 4. [Authorization](4.Authorization.md)
24 | 5. [Views & Layout](5.ViewLayout.md)
25 |
--------------------------------------------------------------------------------
/docs/5.ViewLayout.md:
--------------------------------------------------------------------------------
1 | # View and layout scripts
2 | ZfcAdmin includes an admin layout and index view script, so ZfcAdmin works out of the box. These view scripts are fully customizable, you can turn them off or render other scripts. All options are listed below.
3 |
4 | ## Override admin layout
5 | You can define your own layout script. If you want a custom layout template, you must create a module where this layout is defined. Then the resolver can automatically find a version of the layout if you configure your module correctly. Say you have a module `MyAdmin`, create a module configuration to load view scripts for that module in the `module.config.php`:
6 |
7 | 'view_manager' => array(
8 | 'template_path_stack' => array(
9 | __DIR__ . '/../view'
10 | ),
11 | ),
12 |
13 | The MyAdmin module must contain a `view` directory. Inside this directory, create another directory called `layout` and inside `layout` create a file `admin.phtml`. So this file is located (if your MyAdmin module is under the `module/` directory of your application) at `module/MyAdmin/view/layout/admin.phtml`.
14 |
15 | Make sure MyAdmin is registered in the `application.config.php` and `ZfcAdmin` is located *above* `MyAdmin`. Then your new admin template will be loaded.
16 |
17 | ## Override admin index view script
18 | You can also define the script rendered when you visit `/admin`. The way to solve this is similar to changing the layout (see above), only the location of the view script is different. So create a new module, for example MyAdmin, and enable this configuration:
19 |
20 | 'view_manager' => array(
21 | 'template_path_stack' => array(
22 | __DIR__ . '/../view'
23 | ),
24 | ),
25 |
26 | Then create the folders `zfc-admin/admin` inside the `view` directory. Inside `zfc-admin/admin`, create an `index.phtml` file. So this file is located (if your MyAdmin module is under the `module/` directory of your application) at `module/MyAdmin/view/zfc-admin/admin/index.phtml`.
27 |
28 | Make sure MyAdmin is registered in the `application.config.php` and `ZfcAdmin` is located *above* `MyAdmin`. Then your new index view script will be loaded.
29 |
30 | ## Rename admin layout
31 | If you already have a `layout/admin` layout template and want to use another layout for ZfcAdmin, you can rename the layout used. By default it is `layout/admin` but you can for example configure ZfcAdmin to switch to `layout/backend`. You can enable this configuration to use another layout name:
32 |
33 | 'zfcadmin' => array(
34 | 'admin_layout_template' => 'layout/backend'
35 | ),
36 |
37 | ## Disable layout
38 | If you need a page with a controller where only the view script is rendered, you can disable the layout. Layout disabling works just like any other page outside ZfcAdmin where you disable the layout. To accomplish this, you must terminate the view model in the controller:
39 |
40 | public function indexAction()
41 | {
42 | $model = new ViewModel;
43 | $model->setTerminal(true);
44 |
45 | return $model;
46 | }
47 |
48 | ## Use normal `layout.phtml` layout
49 | You can disable ZfcAdmin to switch to the `layout/admin` layout at all. The routing and navigation still works, but the name of the layout script is untouched. You can enable this configuration to disable layout switching:
50 |
51 | 'zfcadmin' => array(
52 | 'use_admin_layout' => false
53 | ),
54 |
55 | ## Link to documentation pages
56 |
57 | 1. [Introduction](1.Introduction.md)
58 | 2. [Routes](2.Routes.md)
59 | 3. [Navigation](3.Navigation.md)
60 | 4. [Authorization](4.Authorization.md)
61 | 5. [Views & Layout](5.ViewLayout.md)
--------------------------------------------------------------------------------
/src/ConfigProvider.php:
--------------------------------------------------------------------------------
1 |
37 | * @copyright 2012 Jurian Sluiman.
38 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
39 | * @link http://zf-commons.github.com
40 | */
41 |
42 | namespace ZfcAdmin;
43 |
44 | /**
45 | * Class ConfigProvider.
46 | */
47 | class ConfigProvider
48 | {
49 | /**
50 | * Provide dependency configuration for an application integrating i18n.
51 | *
52 | * @return array
53 | */
54 | public function __invoke()
55 | {
56 | return [
57 | 'dependencies' => $this->getDependencyConfig(),
58 | 'view_manager' => $this->getViewManagerConfig(),
59 | 'zfcadmin' => $this->getModuleConfig(),
60 | ];
61 | }
62 | /**
63 | * Provide dependency configuration for an application.
64 | *
65 | * @return array
66 | */
67 | public function getDependencyConfig()
68 | {
69 | return [
70 | 'factories' => [
71 | 'admin_navigation' => Navigation\Service\AdminNavigationFactory::class,
72 | ],
73 | ];
74 | }
75 |
76 | /**
77 | * @return array
78 | */
79 | public function getViewManagerConfig()
80 | {
81 | return [
82 | 'template_path_stack' => [
83 | __DIR__ . '/../view',
84 | ],
85 | ];
86 | }
87 |
88 | /**
89 | * @return array
90 | */
91 | public function getModuleConfig()
92 | {
93 | return [
94 | 'use_admin_layout' => true,
95 | 'admin_layout_template' => 'layout/admin',
96 | ];
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/Controller/AdminController.php:
--------------------------------------------------------------------------------
1 |
38 | * @copyright 2012 Jurian Sluiman.
39 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
40 | * @link http://zf-commons.github.com
41 | */
42 |
43 | namespace ZfcAdmin\Controller;
44 |
45 | use Zend\Mvc\Controller\AbstractActionController;
46 |
47 | /**
48 | * Placeholder controller
49 | *
50 | * This controller is just here in case you have not defined a controller
51 | * behind the 'admin' route yourself. If you haven't, you would otherwise
52 | * get a 404: Page not found error.
53 | *
54 | * If you want to override this controller (and action), create a module and
55 | * put this in the module configuration:
56 | *
57 | *
58 | * array(
61 | * 'routes' => array(
62 | * 'zfcadmin' => array(
63 | * 'options' => array(
64 | * 'defaults' => array(
65 | * 'controller' => 'MyFoo\Controller\OtherController',
66 | * 'action' => 'custom',
67 | * ),
68 | * ),
69 | * ),
70 | * ),
71 | * ),
72 | * );
73 | *
74 | *
75 | * @package ZfcAdmin
76 | * @subpackage Controller
77 | */
78 | class AdminController extends AbstractActionController
79 | {
80 | }
81 |
--------------------------------------------------------------------------------
/src/Module.php:
--------------------------------------------------------------------------------
1 |
37 | * @copyright 2012 Jurian Sluiman.
38 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
39 | * @link http://zf-commons.github.com
40 | */
41 |
42 | namespace ZfcAdmin;
43 |
44 | use Zend\Loader;
45 | use Zend\EventManager\EventInterface;
46 | use Zend\Mvc\MvcEvent;
47 | use Zend\Mvc\Router\RouteMatch as V2RouteMatch;
48 | use Zend\Router\RouteMatch as V3RouteMatch;
49 | use Zend\ServiceManager\Factory\InvokableFactory;
50 |
51 | /**
52 | * Module class for ZfcAdmin
53 | *
54 | * @package ZfcAdmin
55 | */
56 | class Module
57 | {
58 | /**
59 | * @{inheritdoc}
60 | */
61 | public function getAutoloaderConfig()
62 | {
63 | return [
64 | Loader\AutoloaderFactory::STANDARD_AUTOLOADER => [
65 | Loader\StandardAutoloader::LOAD_NS => [
66 | __NAMESPACE__ => __DIR__,
67 | ],
68 | ],
69 | ];
70 | }
71 |
72 | /**
73 | * @{inheritdoc}
74 | */
75 | public function getConfig()
76 | {
77 | $provider = new ConfigProvider();
78 |
79 | return [
80 | 'service_manager' => $provider->getDependencyConfig(),
81 | 'view_manager' => $provider->getViewManagerConfig(),
82 | 'zfcadmin' => $provider->getModuleConfig(),
83 | 'controllers' => [
84 | 'factories' => [
85 | Controller\AdminController::class => InvokableFactory::class,
86 | ],
87 | ],
88 | 'navigation' => [
89 | 'admin' => [],
90 | ],
91 | 'router' => [
92 | 'routes' => [
93 | 'zfcadmin' => [
94 | 'type' => 'literal',
95 | 'options' => [
96 | 'route' => '/admin',
97 | 'defaults' => [
98 | 'controller' => Controller\AdminController::class,
99 | 'action' => 'index',
100 | ],
101 | ],
102 | 'may_terminate' => true,
103 | ],
104 | ],
105 | ],
106 | ];
107 | }
108 |
109 | /**
110 | * @{inheritdoc}
111 | */
112 | public function onBootstrap(EventInterface $e)
113 | {
114 | /** @var \Zend\Mvc\Application $app */
115 | $app = $e->getParam('application');
116 | $em = $app->getEventManager();
117 |
118 | $em->attach(MvcEvent::EVENT_DISPATCH, [$this, 'selectLayoutBasedOnRoute']);
119 | }
120 |
121 | /**
122 | * Select the admin layout based on route name
123 | *
124 | * @param MvcEvent $e
125 | * @return void
126 | */
127 | public function selectLayoutBasedOnRoute(MvcEvent $e)
128 | {
129 | /** @var \Zend\Mvc\Application $app */
130 | $app = $e->getParam('application');
131 | $sm = $app->getServiceManager();
132 | $config = $sm->get('config');
133 |
134 | if (false === $config['zfcadmin']['use_admin_layout']) {
135 | return;
136 | }
137 |
138 | $match = $e->getRouteMatch();
139 | $controller = $e->getTarget();
140 | if (!($match instanceof V2RouteMatch || $match instanceof V3RouteMatch)
141 | || 0 !== strpos($match->getMatchedRouteName(), 'zfcadmin')
142 | || $controller->getEvent()->getResult()->terminate()
143 | ) {
144 | return;
145 | }
146 |
147 | $layout = $config['zfcadmin']['admin_layout_template'];
148 | $controller->layout($layout);
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/Navigation/Service/AdminNavigationFactory.php:
--------------------------------------------------------------------------------
1 |
38 | * @copyright 2012 Jurian Sluiman.
39 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
40 | * @link http://zf-commons.github.com
41 | */
42 |
43 | namespace ZfcAdmin\Navigation\Service;
44 |
45 | use Zend\Navigation\Service\DefaultNavigationFactory;
46 |
47 | /**
48 | * Factory for the ZfcAdmin admin navigation
49 | *
50 | * @package ZfcAdmin
51 | * @subpackage Navigation\Service
52 | */
53 | class AdminNavigationFactory extends DefaultNavigationFactory
54 | {
55 | /**
56 | * @{inheritdoc}
57 | */
58 | protected function getName()
59 | {
60 | return 'admin';
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/view/layout/admin.phtml:
--------------------------------------------------------------------------------
1 | doctype(); ?>
2 |
3 |
4 |
This is the ZfcAdmin interface. Create a view script which resolves to zfc-admin/admin/index
to override this text. Create a view script for layout/admin
to override this surrounding layout.