PHP项目的文件夹结构 [英] Folder structure for a PHP project

查看:95
本文介绍了PHP项目的文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定从头开始完全重写我的旧PHP项目。之前,我每个页面都有一个文件,现在我想用一个入口点来使用MVC模式方法。该项目本身是相当大的,我正在尝试建立自己的框架,所以我可以很好地整合所有的东西。



我已经搜索stackoverflow类似的问题,发现一些,但他们有非常不同的文件夹结构,所以我决定发布自己的。



文件夹结构到目前为止



  / applications 
/ administration
/ private
/ controllers
/ models
/ views
configuration.php
/ public
/ ajax
/ fonts
/ icons
/ images
/ stylesheets
index.php
/网站
/ private
/ controllers
/ models
/ views
configuration.php
/ public
/ ajax
/ fonts
/ icons
/ images
/ stylesheets
index.php
/ backups
/ library
/ helpers
datetime.php
text.php
controller.php
model。详细信息



    $ b $
  • /应用程序 - 我已将管理与正常网站分开,我也将使用不同的子域进行管理。

  • / applications / app / private - 访问该文件夹被nginx阻止。

  • / applications / app / public - 顾名思义,

  • /applications/app/index.php - 每个网站的入口点。

  • / backups - 数据库备份。

  • / library - 基本控制器/模型驻留在此。

  • / library / helpers - 所有在两个网站上使用的助手类都在这里,所以我不需要复制/粘贴到应用程序



主要问题



这是一个很好的方法来构建我的网站还是你会做不同的事情?我可能遇到这种结构有什么陷阱吗?有没有什么我失踪?



所有的帮助是非常感谢!

解决方案

我正在使用类似的结构(使用自制框架,但是从webroot备份)。您可以在私人文件夹中添加一个form文件夹。



我使用它来使控制器更易读。这些表格是一般的目标代码的大墙。将它们放在控制器中的外部文件中是一个好主意。



不要忘记从重写规则中排除公用文件夹,一切都应该是好的:)另外一个解决方法是将index.php放在你的公用文件夹中,并将这个文件夹定义为nginx中的webroot。它阻止远程访问所有其他应该仅由框架使用的文件(如备份文件)。

  / applications 
/管理
/ private
/ controllers
/ models
/ views
configuration.php
/ public< ---- Vhost WebRoot
/ ajax
/ fonts
/ icons
/ images
/ stylesheets
index.php
/网站
/ private
/ controllers
/ models
/ views
configuration.php
/ public< ---- Vhost WebRoot
/ ajax
/ fonts
/ icons
/ images
/ stylesheets
index.php
/ backups
/ library
/ helpers
datetime.php
text.php
controller.php
model.php


I've decided to completely rewrite my old PHP project from the ground up. Before, I had one file for each page and now I'd like to use MVC pattern approach with one point of entry instead. The project itself is quite big and I'm trying to build my own framework so I can integrate everything nicely.

I've searched stackoverflow for similar questions and I've found some but they had quite different folder structures so I decided to post my own.

Folder structure so far

/applications
    /administration
        /private
            /controllers
            /models
            /views
            configuration.php
        /public
            /ajax
            /fonts
            /icons
            /images
            /stylesheets
        index.php
    /website
        /private
            /controllers
            /models
            /views
            configuration.php
        /public
            /ajax
            /fonts
            /icons
            /images
            /stylesheets
        index.php
/backups
/library
    /helpers
        datetime.php
        text.php
    controller.php
    model.php

Details

  • /applications - I've separated administration from the normal website and I'll also use different sub-domain for the administration.
  • /applications/app/private - Access to this folder is blocked by nginx.
  • /applications/app/public - As the name suggests, everything that's visible on the web.
  • /applications/app/index.php - Entry point for each website.
  • /backups - Database backups.
  • /library - Base controllers / models reside here.
  • /library/helpers - All helper classes that will be used in both websites are here so I don't need to copy/paste them into both applications.

Main questions

Is this a good way to structure my website or would you do things differently? Are there any pitfalls I might encounter with this structure? Is there anything I'm missing?

All help is very appreciated!

解决方案

I'm using a similar structure (with homemade framework too but backup out of webroot). You could maybe add a "form" folder in the private folder.

I use this to make controller more readable. The forms are generaly a big wall of object code. Putting them in an external file included in the controller is a good idea.

Don't forget to exclude the public folder from the rewriting rules and everything should be allright :)

An other solution is to put index.php in your public folder and define this folder as your webroot in nginx. It prevent remote access to all other file (like backup file) which should used only by the framework.

/applications
    /administration
        /private
            /controllers
            /models
            /views
            configuration.php
        /public <---- Vhost WebRoot
            /ajax
            /fonts
            /icons
            /images
            /stylesheets
            index.php
    /website
        /private
            /controllers
            /models
            /views
            configuration.php
        /public <---- Vhost WebRoot
            /ajax
            /fonts
            /icons
            /images
            /stylesheets
            index.php
/backups
/library
    /helpers
        datetime.php
        text.php
    controller.php
    model.php

这篇关于PHP项目的文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆