/    Sign up×
Community /Pin to ProfileBookmark

Help trying to understand MVC logic

Ok guys,
I’m about to begin working on a sister site to my current site, however I want to start getting into the habit of moving away from procedural programming. Eventually, I’ll have to redo a lot of my code on my other site to make things cleaner.

Anyway, one problem I’m having is fully grasping the concept of MVC. From what I understand thus far:

Model = Data (or business logic)
View = Representation of Data (how the data will be formated and how the user will see it)
Controller = The connection point of what data to use and how it should be viewed.

From what I understand, all these are in the file structure as folders. I assume afterwards that if you wanted to create the index.php file, that you’d create a new file outside the MVC folders called index, and call the MVC class files respectively creating class objects where needed.

I assume also that the same concept would apply for say a newsupdates.php page where the database request would reside in the model, the html output and representation would reside in the view, and the controller would say get that data and use that view. If I’m also correct, you could essentially make another page called newsarchive.php and reference the same model used in newsupdate.php with the news archive view right?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 09.2010 — I would say your overall grasp is correct. In practice, many (most?) MVC frameworks use one index.php file as the point of entry. Based on the URL it determines which controller object to launch and which method to use as the entry point.

In practice, it seems a lot of people tend to put a lot of the business logic into the controllers, even though in theory it would belong in the models. To me that's generally academic, and I put it wherever it seems most expeditious to do so. ?

If you want to pursue a MVC implementation, I'd suggest using one of those frameworks unless you really want the "fun" of doing it yourself. But if you use one, then you have the advantage of not having to worry about that underlying substrate, testing it, optimizing it, and so forth: just go build the actual stuff you need for your site. I personally am a CodeIgniter fan, if for no other reason it was the first one I tried that "clicked" for me, perhaps in part because its documentation was very good. Zend has a big following, and is perhaps at a slightly lower level: giving you more power at the price of a bit more complexity.

[url=http://codeigniter.com/tutorials/]CodeIgniter video tutorials[/url]
Copy linkTweet thisAlerts:
@adiianDec 11.2010 — The MVC pattern does not specify how to structure your application or how many entry points it should have. However, in practice having each module(model view controller) in a separate directory helps reducing the dependency between different modules.

Regarding the entry points MVC doesn't specify how to dictate the url or which should be the application entry points. Again, for practical reasons it's better to have single entry point(inde.php): Url Filters, Validation, Routing/Redirects and other application logic elements.
×

Success!

Help @XTREEMMAK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...