Created
April 16, 2014 13:58
-
-
Save settermjd/10879937 to your computer and use it in GitHub Desktop.
This file contains 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
// IndexControllerFactory.php | |
namespace YourModule\Controller\Factory; | |
use Zend\ServiceManager\FactoryInterface, | |
Zend\ServiceManager\ServiceLocatorInterface, | |
Zend\ServiceManager\Exception\ServiceNotCreatedException, | |
YourModule\Controller\IndexController; | |
class IndexControllerFactory implements FactoryInterface | |
{ | |
public function createService(ServiceLocatorInterface $serviceLocator) | |
{ | |
$sm = $serviceLocator->getServiceLocator(); | |
try { | |
$cache = $sm->get('Application\Cache'); | |
} catch (ServiceNotCreatedException $e) { | |
$cache = null; | |
} catch (ExtensionNotLoadedException $e) { | |
$cache = null; | |
} | |
$controller = new IndexController($cache); | |
return $controller; | |
} | |
} | |
// IndexController.php | |
use Zend\Cache\Storage\Adapter\AbstractAdapter; | |
class IndexController | |
{ | |
protected $_cache; | |
public function __construct(AbstractAdapter $cache = null) | |
{ | |
if (!is_null($cache)) { | |
$this->_cache = $cache; | |
} | |
} | |
} | |
// module.config.php | |
return array( | |
'controllers' => array( | |
'factories' => array( | |
'YourModule\Controller\Index' => 'YourModule\Controller\Factory\IndexControllerFactory', | |
) | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how i can pass parameters to service on call time . for example to form elements added to form factory :
in form element
now problem is :