This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For universal solution you may want to try this one, it will work for all Controllers within single Module: | |
class Module | |
{ | |
// Evan's changing layout for specific module only | |
public function init(ModuleManager $moduleManager) { | |
$sharedEvents = $moduleManager->getEventManager()->getSharedManager(); | |
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) { | |
$controller = $e->getTarget(); | |
// do your stuff with controller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/cakephp/cakephp | |
git push [email protected]:mg/cakephp.git master |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -e -p "Enter ZF2 module name: " moduleName; | |
moduleNameLowercase=$(echo $moduleName | tr '[A-Z]' '[a-z]'); | |
mkdir -pv ${moduleName}/{config,src/${moduleName}/{Controller/Plugin,Entity,Filter,Form,Mapper,Service,Validator,View/Helper},view/${moduleNameLowercase}/index} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(([^\s]+)?(\.(?i)(jpg|png|gif|bmp|git|phar|txt|json))$) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see http://samsonasik.wordpress.com/ | |
public function onBootstrap(MvcEvent $e) | |
{ | |
$sharedEvents = $e->getApplication()->getEventManager()->getSharedManager(); | |
$sm = $e->getApplication()->getServiceManager(); | |
$sharedEvents->attach('Zend\Mvc\Controller\AbstractActionController','dispatch', | |
function($e) use ($sm) { | |
$controller = $e->getTarget(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see http://giaule.com/2012/11/18/how-to-use-imagick-with-zf2/ | |
public function uploadAction() { | |
$request = $this->getRequest(); | |
if ($request->isPost()) { | |
$adapter = new \Zend\File\Transfer\Adapter\Http(); | |
$adapter->addValidator('Size', false, array('min' => UPLOAD_IMAGE_MIN_SIZE, 'max' => UPLOAD_IMAGE_MAX_SIZE)); | |
$adapter->addValidator('MimeType', true, array('image/jpeg')); | |
$adapter->addValidator('Count', false, array('min' =>1, 'max' => 1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function add($data) { | |
try { | |
/** | |
* @var \Zend\Db\Adapter\Driver\Pdo\Connection | |
*/ | |
$connection = $this->itemTable->adapter->getDriver()->getConnection(); | |
$connection->beginTransaction(); | |
$connection->commit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ($this->resolver('layouts/default')) : ?> | |
<?php $this->render('layouts/default'); ?> | |
<?php endif; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$template = 'non/existant/template'; | |
$resolver = $this->getEvent() | |
->getApplication() | |
->getServiceManager() | |
->get('Zend\View\Resolver\TemplatePathStack'); | |
if (false === $resolver->resolve($template)) { | |
// does not exist | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyModule\Factory; | |
use Zend\ServiceManager\AbstractFactoryInterface; | |
class SomeClassFactory implements AbstractFactoryInterface { | |
// ... some other code | |
/** | |
* Determine if we can create a service with name | |
* |