[fw-general] Re: [zf-contributors] Zend Framework 2.0.0 STABLE Released!

2012-09-18 Thread nuxwin
Stable ??? Really ??? I don't think so



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Zend-Framework-2-0-0-STABLE-Released-tp4656695p4656913.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Re: zf2 form validation

2012-09-18 Thread luk
poashoas wrote
> So here I go, I have a form, I tried to tell the field it has a validator
> or something,
> and I got no idea where to start if I wanna show a message that the email
> address ain't valid.
> 
> So far I have a form working:
*
> The controller:
*
> 
> public function indexAction ()
> {
> $form = new LoginForm();
> return array('form' => $form);
> }
> 
> class Login extends Form
> {
> public function __construct ()
> {
>parent::__construct('myform');
> 
>$this->setAttributes(array(
>   'id' => 'loginForm',
>   'method' => 'post'
>))
>->add(array(
>'name' => 'username',
>'attributes' => array(
>'type' => 'text',
>),
>   'filters' => array(
>  array('StringTrim')
>   ),
>   'validators' => array(
>  array('name' => 'EmailAddress')
>   ),
>   'options' => array(
>'required' => true,
>'label'=> 'Email'
>   )
>))
>->add(array(
> 'name' => 'submit',
> 'attributes' => array(
> 'type' => 'submit',
> 'value' => 'Login'
>),
>));
> }
> }
*
> The view:
*
> 
> echo $this->form()->openTag($form);
> echo $this->formRow($form->get('username'));
> echo $this->formSubmit($form->get('submit'));
> echo $this->form()->closeTag($form);

Try this code for your Email address form element:

$this->add(array(
'name' => 'username',
'options' => array(
'label' => 'Email',
),
'attributes' => array(
'required' => 'required'
),
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'EmailAddress',
'options' => array(
'messages' => array(
\Zend\Validator\EmailAddress::INVALID_FORMAT =>
'Email address format is invalid'
)
)
)
)
));

The above will first apply a filter StringTrim which will remove empty
spaces and then it will validate an Email address and override a standard
message for invalid format. You can remove that option if you want to use a
standard message. For more information about forms you can read here:
http://www.michaelgallego.fr/blog/?p=190
  



-
Cheers,
--
Luke Mierzwa
--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/zf2-form-validation-tp4656907p4656911.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Ralf Eggert
Hi Matthew and Jurian,

> Well, one question I have is: is it really 4 forms? or 1 form with 4
> views? There's a difference. :)

Well, after really thinking about it, currently there is only three
forms. addAction and updateAction use the same saveForm with different
validation groups. The deleteAction form is not really needed, so I can
refactor that. Just the selectForm works different than the saveForm,
since the email field takes incomplete emails in the selectForm for
searching.

> Exactly -- and I'd do this, as this more semantically groups the
> actions.
> 
>> But does that really make sense?
> 
> Yes -- at least in my opinion. :)

Ok, sounds reasonable.

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Jurian Sluiman
2012/9/18 Ralf Eggert 

> Interesting stuff. I am thinking about this, but the rules of thumb
> might not fit on every case I think.
>
> Here is an example controller I use for managing users by an admin:
>
> -
> class AdminController
> {
> public function indexAction()
> {
> // uses select form
> }
>
> public function addAction()
> {
> // uses create form
> }
>
> public function updateAction()
> {
> // uses update form
> }
>
> public function deleteAction()
> {
> // uses delete form
> }
> }
> -
>
> These are 4 actions and 4 forms. Would you really split this up in more
> than one controller?
>

Usually I use 1 controller per entity. Most of the time I have an Index
(list), View and CRUD (Create, Update, Delete) actions.

For the View and Delete, a route param for the id is required. This also
means I can delete the entity "Foo" without a form. You just POST to
/my/foo/delete/12. If you want to have a CSRF check, use the FooForm with
only the CSRF element in your validation group.

The same holds for create and update: they exactly use the same form
FooForm. The create is a POST to /my/foo/create and the update a POST to
/my/foo/update/12. I see no need in using different forms for every action
here :)
-- 
Jurian Sluiman


[fw-general] zf2 form validation

2012-09-18 Thread poashoas
Hi there!

I am a newbie/n00b (or whatever you wanna call me) on ZF2.
I am used to ZF1 and there are big differences, but I am not even a real
programmer.

So here I go, I have a form, I tried to tell the field it has a validator or
something,
and I got no idea where to start if I wanna show a message that the email
address ain't valid.

So far I have a form working:

*The controller:*

public function indexAction ()
{
$form = new LoginForm();
return array('form' => $form);
}

*The Form:*

class Login extends Form
{
public function __construct ()
{
   parent::__construct('myform');

   $this->setAttributes(array(
  'id' => 'loginForm',
  'method' => 'post'
   ))
   ->add(array(
   'name' => 'username',
   'attributes' => array(
   'type' => 'text',
   ),
  'filters' => array(
 array('StringTrim')
  ),
  'validators' => array(
 array('name' => 'EmailAddress')
  ),
  'options' => array(
   'required' => true,
   'label'=> 'Email'
  )
   ))
   ->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Login'
   ),
   ));
}
}

*The view:*

echo $this->form()->openTag($form);
echo $this->formRow($form->get('username'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag($form);



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/zf2-form-validation-tp4656907.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Matthew Weier O'Phinney
-- Ralf Eggert  wrote
(on Tuesday, 18 September 2012, 04:29 PM +0200):
> Hi Matthew,
> 
> > Then you need to break your controller into multiple controllers, as
> > it's managing too much.
> > 
> > The rule of thumb I have is: more than 5-7 actions in a controller:
> > refactor. More than 1-2 forms: refactor. Otherwise, the workflow of the
> > controller becomes too difficult to follow easily.
> 
> Interesting stuff. I am thinking about this, but the rules of thumb
> might not fit on every case I think.
> 
> Here is an example controller I use for managing users by an admin:
> 
> -
> class AdminController
> {
> public function indexAction()
> {
> // uses select form
> }
> 
> public function addAction()
> {
> // uses create form
> }
> 
> public function updateAction()
> {
> // uses update form
> }
> 
> public function deleteAction()
> {
> // uses delete form
> }
> }
> -
> 
> These are 4 actions and 4 forms. Would you really split this up in more
> than one controller?

Well, one question I have is: is it really 4 forms? or 1 form with 4
views? There's a difference. :)

By using setValidationGroup(), you can have a single form representing a
user, but validate different pieces of it based on the action. For the
"add" action, you'd have one set of fields, for update, another, and for
delete, likely simply the user identifier. Your view scripts would
determine how much or little of the form needs to be displayed. As such,
the above would fit into the criteria I outlined quite well

> Here is another controller I have
> 
> -
> class UserController
> {
> public function indexAction()
> {
> }
> 
> public function registerAction()
> {
> // uses create form
> }
> 
> public function updateAction()
> {
> // uses update form
> }
> 
> public function showAction()
> {
> }
> 
> public function activateAction()
> {
> }
> 
> public function loginAction()
> {
> // uses login form
> }
> 
> public function logoutAction()
> {
> }
> 
> public function passwordAction()
> {
> // uses password form
> }
> 
> public function forbiddenAction()
> {
> }
> }
> -
> 
> This controller has 9 actions which use 4 forms. Well, I could move
> loginAction(), logoutAction() and forbiddenAction() to an AuthController
> and maybe registerAction() and activateAction() to a
> RegistrationController.

Exactly -- and I'd do this, as this more semantically groups the
actions.

> But does that really make sense?

Yes -- at least in my opinion. :)

-- 
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Ralf Eggert
Hi Matthew,

> Then you need to break your controller into multiple controllers, as
> it's managing too much.
> 
> The rule of thumb I have is: more than 5-7 actions in a controller:
> refactor. More than 1-2 forms: refactor. Otherwise, the workflow of the
> controller becomes too difficult to follow easily.

Interesting stuff. I am thinking about this, but the rules of thumb
might not fit on every case I think.

Here is an example controller I use for managing users by an admin:

-
class AdminController
{
public function indexAction()
{
// uses select form
}

public function addAction()
{
// uses create form
}

public function updateAction()
{
// uses update form
}

public function deleteAction()
{
// uses delete form
}
}
-

These are 4 actions and 4 forms. Would you really split this up in more
than one controller?

Here is another controller I have

-
class UserController
{
public function indexAction()
{
}

public function registerAction()
{
// uses create form
}

public function updateAction()
{
// uses update form
}

public function showAction()
{
}

public function activateAction()
{
}

public function loginAction()
{
// uses login form
}

public function logoutAction()
{
}

public function passwordAction()
{
// uses password form
}

public function forbiddenAction()
{
}
}
-

This controller has 9 actions which use 4 forms. Well, I could move
loginAction(), logoutAction() and forbiddenAction() to an AuthController
and maybe registerAction() and activateAction() to a
RegistrationController.

But does that really make sense?

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Matthew Weier O'Phinney
-- Ralf Eggert  wrote
(on Tuesday, 18 September 2012, 12:01 PM +0200):
> the only problem I have with these solutions is about injecting form
> objects to a controller or service. I have about five forms for a
> controller and don't need all of them on every page. So injecting them
> in a factory is no solution.

Then you need to break your controller into multiple controllers, as
it's managing too much.

The rule of thumb I have is: more than 5-7 actions in a controller:
refactor. More than 1-2 forms: refactor. Otherwise, the workflow of the
controller becomes too difficult to follow easily.

-- 
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Matthew Weier O'Phinney
-- Robert Basic  wrote
(on Tuesday, 18 September 2012, 11:40 AM +0200):
> On 17 September 2012 17:14, Matthew Weier O'Phinney  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| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Re: Event driven / Wigets / Form generation

2012-09-18 Thread luk
nuxwin wrote
> I am facing a small problem:
> 
>  I've two modules:
> 
> DomainsManager
> DnsManager (Optional module)
> 
> The first module provides an action (addDomain) that allows an user to add
> a new domain via a form.
> 
> I want be able to extend that form with a partial view/form pulled from
> the DnsManager module (if activated) to allow the user to specify whether
> or not the DNS zone for that domain must be generated.
> 
> I'm thinking about a specific event listener (provided by the DnsManager
> module) to listen on the 'onAddDomain' event (provided the DomainManager
> module) but I'm not sure it's the good way to do. If I do that way, that
> mean that for each request, I will have to "register" that listener ?,
> even if the current route do not match for an action provided by the
> DomainManager module ?
> 
> To resume, what I want do is a kind of widget system but I want avoid too
> much hard dependencies between the modules. I would also avoid to use the
> forward plugin into my module controllers since that involve hard
> dependencies.

You could do a check for loaded/active Modules on loadModules.post event in
your Module.php class firstly. Then in your getControllerConfig you can use
a factory and ServiceManager to inject appropriate Form based on the Modules
check result. Your DnsManager Form can extend a DomainsManager one or you
could just add another fieldset to the DomainsManager Form.



-
Cheers,
--
Luke Mierzwa
--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Event-driven-Wigets-Form-generation-tp4656890p4656902.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Use Zend\Stdlib\Parameters for select form parameters?

2012-09-18 Thread Ralf Eggert
Hi,

I have a select form to select some users. This has a field to search
for a email adress or an select to choose all users with a selectable
status. All my other user forms get my user entity binded to. But this
feels a little wrong here.

Now I found Zend\Stdlib\Parameters and thought if this might be a good
choice for implementing the select form parameters.

Any thoughts?

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Re: module.config.php controllers

2012-09-18 Thread Marco Pivetta
Hey lode,

It may simply be possible to attach an abstract service factory to the
controller loader. That allows you to get services with a number of names
you could decide dinamically. Do it carefully though, since you are linking
services with URLs and you don't want to expose too much.

Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com



On 18 September 2012 14:40, lode [via Zend Framework Community] <
ml-node+s634137n4656899...@n4.nabble.com> wrote:

> Dear Matthew,
>
> Thanks for clearing that up I wasn't aware it's a actually a feature
> instead of a bug.
> Could indeed write my own piece of code to bypass it if need be.
>
> Regards
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://zend-framework-community.634137.n4.nabble.com/module-config-php-controllers-tp4656864p4656899.html
>  To unsubscribe from Zend Framework Community, click 
> here
> .
> NAML
>




--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/module-config-php-controllers-tp4656864p4656900.html
Sent from the Zend Framework mailing list archive at Nabble.com.

[fw-general] Re: module.config.php controllers

2012-09-18 Thread lode
Dear Matthew,

Thanks for clearing that up I wasn't aware it's a actually a feature instead
of a bug.  
Could indeed write my own piece of code to bypass it if need be.

Regards



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/module-config-php-controllers-tp4656864p4656899.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] AW: Replacing the menu helper with custom helper for twitters bootstrap menues

2012-09-18 Thread Marc Tempelmeier
And I got it, if anyone needs it later:

public function getViewHelperConfig()
{
return array(
'factories' => array(
'navigation' => function(HelperPluginManager $pm) {
$helper = new \Zend\View\Helper\Navigation;

$pm->injectRenderer($helper);

$helper->setServiceLocator($pm->getServiceLocator());

$helper->getPluginManager()->setInvokableClass('menuBootstrap', 
'Application\View\Helper\Navigation\MenuBootstrap');

return $helper;
 }
 )
 );
}

The new helper needed the renderer injected. Jurians suggested to use an 
initializer, but thats black magic at the moment.

Greetings :)


-Ursprüngliche Nachricht-
Von: Marc Tempelmeier 
Gesendet: Dienstag, 18. September 2012 11:48
An: 'fw-general@lists.zend.com'
Betreff: AW: Replacing the menu helper with custom helper for twitters 
bootstrap menues

Ok,

I narrowed it down further, in the HelperPluginManager in method 
injectRenderer() I have no renderer, line 123 returns null. 

My own menu class is just:
class Menubootstrap extends Menu
{
}

any suggestions? :)

Greetings

Marc

-Ursprüngliche Nachricht-
Von: Marc Tempelmeier 
Gesendet: Montag, 17. September 2012 16:08
An: 'fw-general@lists.zend.com'
Betreff: Replacing the menu helper with custom helper for twitters bootstrap 
menues

Hi,

just another Navigation question :)

I want to replace the menu helper of \Zend\View\Helper\Navigation with my own 
implementation which outputs me the correct html for 
twitters bootstrap menus.

I narrowed it down to:

public function getViewHelperConfig()
{
 return array(
 'factories' => array(
 'navigation' => function(HelperPluginManager $pm) {
$helper = new \Zend\View\Helper\Navigation;

$pluginManager = new 
\Zend\View\Helper\Navigation\PluginManager();
$pluginManager->setInvokableClass('menu', 
'Zend\View\Helper\Navigation\Menubootstrap');

$helper->setServiceLocator($pm->getServiceLocator());
$helper->setPluginManager($pluginManager);

return $helper;
 }
 )
 );
}

It works as intented if I set the key for 'menu' direct in 
\Zend\View\Helper\Navigation\PluginManager(), but not if I set it with the 
factory above.
I´ll always get:

Fatal error: Call to a member function plugin() on a non-object in D:\Zend 
Server\Apache2\htdocs\komplex\vendor\Zend2\View\Helper\AbstractHtmlElement.php 
on line 74

I know that the class doesn´t belong in that folder, its there to eliminate the 
possibility of path errors and will go to the correct path after that. :)

Greetings and thx in advance

Marc aka G0re



--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Ralf Eggert
Hi again,

ok, forget it. I missed to implement this line:

$eventManager->setIdentifiers(array(__CLASS__, get_called_class()));

within the method setEventManager() in the class that implements the
EventManagerAwareInterface.

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Robert Basic
On 18 September 2012 11:54, Robert Basic  wrote:
> Marco, Jurian,
>
> thanks guys. Odd, I tried exactly that, and didn't work, and now it
> does. I'll just file this under the "did not get enough sleep last
> night" issues :(
>
> Thanks again.

Think I had it enough for today with this...

The error I was getting is that the controller could not be mapped,
where as the real problem was that the service manager was throwing
Zend\ServiceManager\Exception\ServiceNotFoundException

-- 
~Robert Basic;
http://robertbasic.com/

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Ralf Eggert
Hi,

the only problem I have with these solutions is about injecting form
objects to a controller or service. I have about five forms for a
controller and don't need all of them on every page. So injecting them
in a factory is no solution.

Matthew suggested to use the event manager to trigger them on the fly
but I did not get that working.

Any suggestions?

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] AW: Replacing the menu helper with custom helper for twitters bootstrap menues

2012-09-18 Thread Marc Tempelmeier
Ok,

I narrowed it down further, in the HelperPluginManager in method 
injectRenderer() I have no renderer, line 123 returns null. 

My own menu class is just:
class Menubootstrap extends Menu
{
}

any suggestions? :)

Greetings

Marc

-Ursprüngliche Nachricht-
Von: Marc Tempelmeier 
Gesendet: Montag, 17. September 2012 16:08
An: 'fw-general@lists.zend.com'
Betreff: Replacing the menu helper with custom helper for twitters bootstrap 
menues

Hi,

just another Navigation question :)

I want to replace the menu helper of \Zend\View\Helper\Navigation with my own 
implementation which outputs me the correct html for 
twitters bootstrap menus.

I narrowed it down to:

public function getViewHelperConfig()
{
 return array(
 'factories' => array(
 'navigation' => function(HelperPluginManager $pm) {
$helper = new \Zend\View\Helper\Navigation;

$pluginManager = new 
\Zend\View\Helper\Navigation\PluginManager();
$pluginManager->setInvokableClass('menu', 
'Zend\View\Helper\Navigation\Menubootstrap');

$helper->setServiceLocator($pm->getServiceLocator());
$helper->setPluginManager($pluginManager);

return $helper;
 }
 )
 );
}

It works as intented if I set the key for 'menu' direct in 
\Zend\View\Helper\Navigation\PluginManager(), but not if I set it with the 
factory above.
I´ll always get:

Fatal error: Call to a member function plugin() on a non-object in D:\Zend 
Server\Apache2\htdocs\komplex\vendor\Zend2\View\Helper\AbstractHtmlElement.php 
on line 74

I know that the class doesn´t belong in that folder, its there to eliminate the 
possibility of path errors and will go to the correct path after that. :)

Greetings and thx in advance

Marc aka G0re



--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Ralf Eggert
Hi Robert,

if you want to use a factory class you can do it like this:

/module/User/config/module.config.php
-
'controllers' => array(
'invokables' => array(
'user-admin' => 'User\Controller\AdminController',
),
'factories' => array(
'user'   => 'User\Controller\UserControllerFactory',
),
),
-

/module/User/src/Controller/UserControllerFactory.php
-

namespace User\Controller;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class UserControllerFactory implements FactoryInterface
{
public function createService(
ServiceLocatorInterface $serviceLocator
)
{
$service= $serviceLocator->getServiceLocator()
 ->get('User\Service\User');
$controller = new UserController();
$controller->setUserService($service);
return $controller;
}
}

-

My UserController could also use the constructor to accept dependencies.

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Robert Basic
Marco, Jurian,

thanks guys. Odd, I tried exactly that, and didn't work, and now it
does. I'll just file this under the "did not get enough sleep last
night" issues :(

Thanks again.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Jurian Sluiman
2012/9/18 Robert Basic 

> On 17 September 2012 17:14, Matthew Weier O'Phinney 
> 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.


I agree with Matthew, I prefer injecting dependencies in my controllers too.

If you have module class with a getControllerConfig() method, you could
return factory configuration as well. I usually include the controller
factories from a separate file:

public function getControllerConfig()
{
return include __DIR__ . '/config/controller.config.php';
}

Such controller.config.php can look like this:

 array(
'MyModule\Controller\FooController' => function($sm) {
$service =
$sm->getServiceLocator()->get('MyModule\Service\DependencyClass');

$controller = new Controller\FooController($service);
return $controller;
},
),
);
-- 
Jurian Sluiman


Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Marco Pivetta
@Robert:

array(
'controllers' => array(
'factories' => array(
'my_controller' => function (ServiceLocator $sl) {
return new MyController($sl->get('a_dependency'),
$sl->get('another_dependency'));
},
),
),
);

This works also with Zend\Di for development purposes, as I've blogged at
http://ocramius.github.com/blog/zend-framework-2-controllers-and-dependency-injection-with-zend-di/

Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com



On 18 September 2012 11:40, Robert Basic  wrote:

> On 17 September 2012 17:14, Matthew Weier O'Phinney 
> 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.
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Ralf Eggert
Hi Matthew,

> I personally have been recommending the first way. The primary reasons
> are:

Yes, meanwhile I prefer the first way as well. I guess the quick start
should be changed, because at the moment it shows the second way for the
action controller:

http://zf2.readthedocs.org/en/latest/user-guide/database-and-models.html#using-servicemanager-to-configure-the-database-credentials-and-inject-into-the-controller

Regards,

Ralf

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




Re: [fw-general] [ZF2] Injecting objects to a controller, or getting objects from the service locator?

2012-09-18 Thread Robert Basic
On 17 September 2012 17:14, Matthew Weier O'Phinney  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.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com