-- Robert Basic <[email protected]> wrote
(on Tuesday, 18 September 2012, 11:40 AM +0200):
> On 17 September 2012 17:14, Matthew Weier O'Phinney <[email protected]> wrote:
> >
> > I personally have been recommending the first way.
>
> Any example for getting controllers via factories? I've been through
> the docs, code, tests, examples, but fail to figure it out :( I can
> get anything else to work via factories, but not controllers. The only
> way I can get controllers is using the 'controllers' => array(
> 'invokables' => array( ... )) stuff, but that doesn't allow me to
> inject dependencies.
https://github.com/weierophinney/PhlyPeep/blob/master/src/PhlyPeep/Service/PeepControllerFactory.php
The trick is remembering that if the service is managed by a plugin
manager, you need to pull the app service locator instance from that
plugin manager. So, in that example, you'll see that in the factory, I
named the argument "controllers" -- that reminds me that this is managed
by the ControllerManager, and I have to pull the app service locator
from it -- which is what the first line of that factory does. Then I can
pull deps from there, and inject them in my newly created controller.
I do the same with view helpers in that project:
https://github.com/weierophinney/PhlyPeep/blob/master/src/PhlyPeep/Service/PeepViewFormFactory.php
Notice in that example I use the verbiage "helpers" to refer to the
helper manager.
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]