VOTEMIKE
VOTEMIKE

Reputation: 11

Does the MVC concept apply to static PHP pages?

I am trying to build my own PHP MVC framework.

At the moment I am creating a simple 2 page website where each page extends a template page so that I don't have to worry about the meta tags, header, navigation and footer when creating new pages.

I am trying to figure out a way to spilt this into the separate components of MVC but can't

This leads me to believe that MVC isn't necessarily the way forward with this framework.

So, does the MVC concept apply to static(by static I mean the only user input is clicking on links, no logging in or anything) PHP pages?

Upvotes: 1

Views: 610

Answers (3)

Sebas
Sebas

Reputation: 21532

First of all, mvc is NEVER necessary. This is just a pattern recognized to be handy providing organization, robusty, safety...

Then, if you want my opinion the earlier you get to be familiar with it implementing it in your static pages the easier it is going to be to go ahead with your next pages.

Upvotes: 1

Cata Cata
Cata Cata

Reputation: 166

Since your pages need a programing language to change the content , do something with the user input etc , it's not that static at all. They are static when u use only markup and styling languages.

It's hard to say if ur project needs a solid architecture. For static pages , you don't need mvc. For your 2 page project again i think you don't need mvc unless your pages are very dynamic ( 1 page can have several states) .

You should read more about the structure, achitecture of an application if you really want to make your own framework. Usually only medium/big applications need a solid structure/architecture (ex. : mvc).

Final answer : i don't think your app needs mvc .
P.S. : It's good to make your own mvc framework , you learn alot of things . But it will take alot to finalise it if your doing it alone (if u want to make it better than the existing ones ). There is no solid (nearly perfect :) ) php mvc framework outhere. Php community lacks a good and world wide accepted framework. Many frameworks but all have theyr pros and cons. I even heared some devs saying zend mvc is more of a library .

Upvotes: 2

tereško
tereško

Reputation: 58444

Do you need MVC

  • Can the MVC concept apply to a website with static pages? Yes, it can.
  • Should you do use it? No, unless you expect the project to grow.

MVC architecture, at the core of it, is about separating the business logic from the presentational logic.

In (what you call) static site, the only role of model layer (yes, it is a layer, not a class) would be to fetch content from either cache or database. In this case you will get more frame then work, because setting up a MVC structure would take more code, then the useful parts.

Should you build a framework

Definitely make one. In PHP community this almost like a rite of passage. If you have not made at least few frameworks, you are not a real PHP developer.

Though, you should keep in mind, that it will take at least 3 iterations for you to build something that does not suck. And that is assuming that you actually study OOP principles instead of mimicking some other framework.

What would be a better options for a tiny project

Instead of writing a full MVC framework, try to write something that follows the spirit of it.

There are two things you should start from:

  1. you application should have Single Point of Entrance. This would mean, if user writes http://who.cares/article/1 , then you should rewrite the URL to index.php?url=article/1

  2. separate the concerns. Basically you have 3 different thins to do in such applications:

    • parse the user's request
    • fetch the data
    • display the collected information

For the last part you might benefit from looking at this article. For the rest, you will have to decide on your own.

Just don't the ancient mysql_* functions for collecting data from database (if you have any). They are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. If you cannot decide, this article will help to choose. If you care to learn, here is a quite good PDO-related tutorial.

Upvotes: 3

Related Questions