Minnesota PHP User Group Message Board MNPHP Discussion Forum › MVC Architecture- Best Practice Question

MVC Architecture- Best Practice Question

Josh S.
user 68215092
Minneapolis, MN
Post #: 1

My question here involves the "view" piece of a Model-View-Controller architecture using Zend-2, the way I want to design it is such that the main view/html template (header, footer, nav menu) and all of its associated files are logically bundled together, and when a user makes a request to change pages/controllers or something, then I can just inject some module view with the proper data and send/display it to the template already sitting there.

Am I thinking about this correctly? What are some of the Zend classes I should start looking into, I have read about PhpRenderer a little bit, and had tried messing with layouts in Zend 1.14 I believe(?) and didn't have much luck.

I am more or less looking for a way to have a valid html page template that won't change very often, and be able to quickly and efficiently inject different view pages into the main template to render the final view that the user sees.


Anyone got any advice or helpful references for me?
Jonathan S.
jsundquist
Group Organizer
Saint Paul, MN
Post #: 9
Josh,

What it sounds like is you need to work with a layout and then your standard views. Your layout may contain the header, footer, and nav menu that doesn't change. Then your view will contain what ever is needed for that particular action you are working with on the controller.

- Jon
Daniel J. P.
danieljpost
Minneapolis, MN
Post #: 89
I agree with Jonathan.

What I suggest is that you get a hold of the Zend Skeleton Application and look around inside.

The "layout" file you're looking for is in module/Application/view/layout/layout.ph­tml

I strongly recommend sticking with the conventions used in the Skeleton application. You'll thank me later.

Much later, after you've figured it out...
Josh S.
user 68215092
Minneapolis, MN
Post #: 2
I have messed with the skeleton application a fair amount, and tried messing with the layout.phtml file that is provided and it wasn't very straight forward to me.

I tried to do what I described in my first post with the layout.phtml but what would happen is it would parse the view file(s) I provided, then parse the layout.phtml file.. the problem is that any html found in the view file would get discarded, and the only html being displayed was from the layout.phtml file. In addition to this I was not able to pass along any data to the layout.phtml file, I was trying to pass a test string through the Mvc layer that I initialized in the bootstrap and the string never made it to the layout file.

I explored trying to change the parsing order, so the layout would be parsed first, thinking that I'd have a valid html page to add things on top of, instead of the other way around.

In regard to sticking with the skeleton application structure, do you have a few brief reasons for why I should do this? I hear that the combination of php + Zend2 is incredibly slow.

Any thoughts on this?
Daniel J. P.
danieljpost
Minneapolis, MN
Post #: 90
I'm using something like this in my work:

IndexController.php:
public somethingAction() {
// awesome stuff happens
return new ViewModel(array('displayvariable'=>$d­isplayvariable));
}

layout.phtml
here's where I display something <?php echo $this->something?>

something.phtml
<b><?php echo $this->displayvariable?></b>­
Josh S.
user 68215092
Minneapolis, MN
Post #: 3
Thanks! I'll keep digging around when I get some time this week.
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy