dev-master
9999999-devZF2 Snipped Module to generate heavy views as snippets and lower the application response time
MIT
The Requires
- php >=5.3.3
The Development Requires
by Marco Rieger
cache php zf2 zend zend-framework
ZF2 Snipped Module to generate heavy views as snippets and lower the application response time
ZF2 Module to save heavy views as prerendered snippets in cache and lower the application response time on request, (*1)
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
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, ) ) ), ),
create a zf2 console route and point a crontab to the route to pre generate all views that are used in your application, (*5)
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>
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 }
ZF2 Snipped Module to generate heavy views as snippets and lower the application response time
MIT
cache php zf2 zend zend-framework