change view script from controller factory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

change view script from controller factory

DimaD
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Hi,

I have 2 helpers. A helper has a form, and a mapper to handle the database interaction. I pass these helpers to the controller using a controller factory. The controller handles phones and addresses of a party that is either a person or an organization. Because a party is a person or an organization, it has different data, so the controller factory also passes the object: PersonObject or OrganizationObject with the party-specific data into the controller.

The 2 helpers are the same for both party types. But in the view script, I want to show the party-specific data, and here is my problem: I need to change the view script based on the object that the controller factory passes to the controller. I thought of having a two different controllers, but it's an overkill: the view script is 90% the same, except for that 10% party-specific info that comes from the database into the party object.

How to change the view script from the controller factory? By changing here, I mean slightly different html layout with the party specific data.
Reply | Threaded
Open this post in threaded view
|

Re: change view script from controller factory

Marco Pivetta
This post has NOT been accepted by the mailing list yet.
Hi DimaD,

On 22 May 2016 at 14:30, DimaD [via Zend Framework Community] <[hidden email]> wrote:
Hi,

I have 2 helpers. A helper has a form, and a mapper to handle the database interaction. I pass these helpers to the controller using a controller factory. The controller handles phones and addresses of a party that is either a person or an organization. Because a party is a person or an organization, it has different data, so the controller factory also passes the object with the party-specific data into the controller.

The 2 helpers are the same for both party types. But in the view script, I want to show the party-specific data, and here is my problem: I need to change the view script based on the object that the controller factory passes to the controller.

This seems like a controller concern to me.
 
I thought of having a two different controllers, but it's an overkill: the view script is 90% the same, except for that 10% party-specific info that comes from the database into the party object.

You can simply build the same controller twice, but add the view name as a different constructor parameter, then make that concern part of the factory.

Marco Pivetta

http://twitter.com/Ocramius     

http://ocramius.github.com/

Reply | Threaded
Open this post in threaded view
|

Re: change view script from controller factory

DimaD
This post has NOT been accepted by the mailing list yet.
Hey Marco,


Thanks a lot for your help (2nd time already). :-) Do you think it's an overkill if I instantiate the appropriate ViewModel in the controller and simply pass it to the controller from the factory using dependency injection?

PS: read a couple of your blog posts, by the way. Became a kinda fan of your work now. :-)
Reply | Threaded
Open this post in threaded view
|

Re: change view script from controller factory

Marco Pivetta
This post has NOT been accepted by the mailing list yet.
Hi DimaD,

On 25 May 2016 at 08:03, DimaD [via Zend Framework Community] <[hidden email]> wrote:
Thanks a lot for your help (2nd time already). :-) Do you think it's an overkill if I instantiate the appropriate ViewModel in the controller and simply pass it to the controller from the factory using dependency injection?

The ViewModel is still to be instantiated by the controller, but the template name (passed to the view model) is provided by the factory to the controller.

Cheers,

Reply | Threaded
Open this post in threaded view
|

Re: change view script from controller factory

DimaD
This post has NOT been accepted by the mailing list yet.
Thanks very much, Marco!