0

I'm trying to learn the MVC design pattern for PHP development and I have a couple of questions concerning view structure.

  1. I keep seeing "Views are not templates!" plastered everywhere where I read about MVC. But how do I include stuff like headers, navbars and footers? If I have html that should be shared by all views, how do I include it around the view without a template?

  2. I also read on another thread in stack overflow that views should never have require statements, and that they are the ones that should be required. But what about a case where I have a view that should be required in multiple views? Let's say that some views have a few lines that spit out a list, it would be more logical to reuse the code using require statements within a view than to rewrite it for every view, but this is apparently against the nature of views.

Thanks.

1
  • 1
    Ify ou aren't referring to a specific framework like CakePHP, for example, then you mean MVC Design Pattern, rather than framework Commented Jun 12, 2014 at 20:58

1 Answer 1

2

A template isn't a view, but a view could use a template. Templates are just re-usable architecture/design that a view can be based on. Views are typically a specific page or page type.

Views should also have little to no business logic in it, and should be focused on the layout and design, hence why there should be little or no requires.

If your view is using a template, then you likely don't need to include things like footers and headers, depending on the template system you are using. But if you are creating the view without a template, you will likely have to include those on the view yourself.

Focus on maintainability, scalability and a separation of design and logic, and make your code re-usable whenever possible.

Sign up to request clarification or add additional context in comments.

1 Comment

Header is a template, footer is a template .. and the page contetnet has some templates. And a view pulls necessery data and assembles the page from thos (and some aothers, maybe) templates. Views do not have "business logic" but they do have UI logic.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.