2017 © Pedro Peláez
 

library zf2-snippster

ZF2 Snipped Module to generate heavy views as snippets and lower the application response time

image

ins0/zf2-snippster

ZF2 Snipped Module to generate heavy views as snippets and lower the application response time

  • Wednesday, October 15, 2014
  • by ins0
  • Repository
  • 2 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

zf2-snippster

ZF2 Module to save heavy views as prerendered snippets in cache and lower the application response time on request, (*1)

todo

  • [ ] tests
  • [ ] view helper
  • [ ] controller helper

Quick start

Install via Composer

In the require key of composer.json file add the following, (*2)

"ins0/zf2-snippster": "dev-master"

Run the Composer update command, (*3)

$ composer update

cache adapter

edit the module.config.php to set your pref. cache adapter snippster works great with redis or memcache, (*4)

'snippster_configuration' => array(
    'cache' => array(
        'adapter' => 'Zend\Cache\Storage\Adapter\Redis',
        'options' => array(
            'server' => array(
                'host' => '127.0.0.1',
                'port' => 6379,
            )
        )
    ),
),

example

create a zf2 console route and point a crontab to the route to pre generate all views that are used in your application, (*5)

Generate Snippets

config.module.php, (*6)

'view_manager' => array(
  'template_map' => array(
      'snippster-product-list-item' => __DIR__ . '/../view/snippster/example/product/list-item.phtml',
  )
)

ConsoleExampleController.php, (*7)

function snippsterCreateExampleProductViews()
{
    /** @var \Snippster\Service\Snippster $snippster */
    $snippster = $this->getServiceLocator()->get('Snippster');

    $products = array(
        array('id' => 1, 'name' => 'Test Product1'),
        array('id' => 2, 'name' => 'Test Product2'),
        array('id' => 3, 'name' => 'Test Product3'),
        array('id' => 4, 'name' => 'Test Product4'),
        array('id' => 5, 'name' => 'Test Product5'),
        array('id' => 6, 'name' => 'Test Product6'),
    );

    foreach($products as $product)
    {
        $viewSnippet = new \Snippster\Entity\ViewSnippet('product-list-item', $product['id']);
        $viewSnippet->setTemplate('snippster-product-list-item');
        $viewSnippet->setVariables($product);

        $snippster->saveViewSnippet($viewSnippet);
    }
}

snippster/example/product/list-item.phtml, (*8)

<div class="product">
    <h1><?php echo $this->escapeHtml($this->name); ?>
    <hr>
    More heavy stuff to build this view
</div>

Request Snippets

controller request view snippet example, (*9)

function productListAction()
{
    /** @var \Snippster\Service\Snippster $snippster */
    $snippster = $this->getServiceLocator()->get('Snippster');

    $html = $snippster->getViewSnippet('product-list-item', 4);
    // get pre rendered product html - do stuff
}

The Versions

15/10 2014

dev-master

9999999-dev

ZF2 Snipped Module to generate heavy views as snippets and lower the application response time

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

cache php zf2 zend zend-framework