开发者

Is this a good layout for a large PHP site?

开发者 https://www.devze.com 2022-12-19 05:05 出处:网络
The whole MVC design confuses me a little bit as I have never used it.Below is the general layout of my current project...

The whole MVC design confuses me a little bit as I have never used it. Below is the general layout of my current project...

The account folder holds basicly all my core files for my user system

root/account/login.php

root/account/home.php

root/account/logout.php

root/account/settings.php

Then I have a seperate folder for each "module" (forums, blogs, etc)

root/forums/ root/blogs/

root/mail/

Then any functions and classes and config files are loaded from an includes directory like this

root/includes/classes/ root/includes/bootstrap.php //this file autoloads the class files needed and ensures a DB connection sitewide

Most of the "work" is done inside the class files. Obviously I left out hundreds of files and several other folder开发者_StackOverflow中文版s ( css/ js/ images/ )

So I am wondering, does this seem like a good design for a large scale site? This isn't considered MVC is it? And Please do not refer me to a Framework.


No, it doesn't seem like you are necessarily using MVC. Most of the time they are grouped by their real MVC names:

If I had to guess how you are splitting your files, your structure could look like this

views/
  account/
    login.php
    home.php
    settings.php
    logout.php
controllers/  #maybe what you call modules
  account.php
  blog.php
  mail.php
models/       #maybe what you call "classes" are models
  account.php
  blog_entry.php
  comment.php

Just a quick reference:

  • M odel = Class that handles all interaction with the database for a specific object/function and normally has a 1 to 1 ratio with a database record (And of course has relationships to other models).
  • V iew = Handles displaying content to the user. No business code (or very little) should be contained in these files. Database access, for example, should not be performed in the view.
  • C ontroller = Script that receives the requests from the user, decides which models to get involved, performs the necessary action (passing off as much as makes sense to individual models), then prepares the data to show the user and sends that to the view for display.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号