Modules

Zend Framework 2.0 introduces a new and powerful approach to modules. This new module system is designed with flexibility, simplicity, and re-usability in mind. A module may contain just about anything: PHP code, including MVC functionality; library code; view scripts; and/or public assets such as images, CSS, and JavaScript. The possibilities are endless.

ShineISP is ready to "inject" new modules, services and much more to increase the number of features. So if you would like to add a new feature, clone it, add your module and share it. If the module is well written we will include it in our next release.

Module Structure

Each module page respect a standard structure for the DocType, CSS, HTML, Javascript, etc..

For instance we can analize this module: Admin Open this file:

/module/admin/view/layout/admin.phtml

This is only a simple html file. You can edit it to add a new link or change the layout style.

<?php echo $this->doctype(); ?>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <?php echo $this->partial('partial/admin-head.phtml'); ?> 
    </head>
  <body>
        <?php echo $this->partial('partial/admin-header.phtml'); ?>     
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <?php echo $this->flashMessage(); ?>
                    <?php echo $this->content; ?>
                </div>
            </div>
        </div>
        <?php echo $this->inlineScript(); ?>       
    </body>
</html>

DocType

Doctype can be changed by code but in order to print it you have to use:

<?php echo $this->doctype(); ?>

Partials

The partials are a snipped of html code or html that you split in various files. In order to read them you have to call them in this way:

   <?php echo $this->partial('partial/admin-head.phtml'); ?>

In this way you call a file within the module, in this case the admin module, in this path:

/module/Admin/view/partial/admin-head.phtml

Helpers

A helper is simply a class that implements the interface Zend\View\Helper. Helper simply defines two methods, setView(), which accepts a Zend\View\Renderer instance/implementation, and getView(), used to retrieve that instance. Zend\View\PhpRenderer composes a plugin broker, allowing you to retrieve helpers, and also provides some method overloading capabilities that allow proxying method calls to helpers.

In this case the flashMessage view helper shows a message before the body content. This is the syntax:

<?php echo $this->flashMessage(); ?>

CSS files

If you need to add a new CSS file in your layout template you have to add a new item within the Module.php in this way:

$headLink = $sm->get('viewhelpermanager')->get('headLink');
$headLink->appendStylesheet('/css/admin/bootstrap-switch.css', 'all')
         ->appendStylesheet('/css/admin/bootstrap-typeahead.css', 'all')
         ->appendStylesheet('/css/admin/admin.css', 'all');

then in the partial file or in the layout file you have to use the headLink helper:

<?php echo $this->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/img/favicon.ico')) ?>

Javascript files

If you need to add a new Javascript file in your admin layout you have to add it within the Module.php file as a simple array of links.

$inlineScript = $sm->get('viewhelpermanager')->get('inlineScript');
$inlineScript->appendFile('/js/admin/bootstrap-hogan-2.0.0.js')
             ->appendFile('/js/admin/bootstrap-typeahead.min.js')
             ->appendFile('/js/admin/bootstrap-switch.min.js')
             ->appendFile('/js/admin/admin.js');

Then in your layout you have to call the helper inlineScript() in this way:

<?php echo $this->inlineScript(); ?>

results matching ""

    No results matching ""