Skip to content

Instantly share code, notes, and snippets.

@settermjd
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save settermjd/f5d8c161936d166420e9 to your computer and use it in GitHub Desktop.
Save settermjd/f5d8c161936d166420e9 to your computer and use it in GitHub Desktop.
<?php
/**
* This class allows the Controller to be instantiated as a factory by the ServiceManager
*/
namespace BabyMonitor\Controller\Factories;
use Zend\ServiceManager\FactoryInterface,
Zend\ServiceManager\ServiceLocatorInterface,
Monitor\Controller\MonitorController;
class MonitorControllerFactory implements FactoryInterface
{
protected $cache = null;
protected $monitorTable = null;
public function createService(ServiceLocatorInterface $serviceLocator)
{
$sm = $serviceLocator->getServiceLocator();
if ($sm->has('Monitor\Tables\MonitorTable')) {
$this->monitorTable = $sm->get('Monitor\Tables\MonitorTable');
}
if ($sm->has('Monitor\Cache\Application')) {
$this->cache = $sm->get('Monitor\Cache\Application');
}
$config = $sm->get('Config');
$appConfig = (array_key_exists('app', $config)) ? $config['app'] : null;
$controller = new MonitorController($this->monitorTable, $appConfig, $this->cache);
return $controller;
}
}
<?php
/**
* The Monitor Controller
*
*/
namespace BabyMonitor\Controller;
use Monitor\Model\MonitorModel;
use Monitor\Tables\MonitorTable;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Adapter\Iterator;
use Zend\Paginator\Paginator;
use Zend\View\Model\ViewModel;
use Zend\Db\ResultSet\ResultSetInterface;
class MonitorController extends AbstractActionController
{
/**
* @var MonitorTable
*/
protected $monitorTable;
public function __construct(MonitorTable $monitorTable)
{
$this->monitorTable = $monitorTable;
}
}
<?php
// module.config.php
return array(
'controllers' => array(
'invokables' => array(),
'factories' => array(
'Monitor\Controller\Monitor' =>
'MonitorMonitor\Controller\Factories\MonitorControllerFactory',
)
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment