PHP的项目结构 [英] Project structure for PHP

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

问题描述

我是PHP新手,想了解php项目的目录结构。我有Java经验,在Java中,src包含Java源文件,WEB-INF包含lib和jsp页面。我们在PHP中是否有任何类似的标准目录结构?
我们也像在Java中一样在PHP中进行分层(例如,Web,Service,DAO层)

I am new to PHP and want to know the directory structure for the php projects. I have experience in Java and in java we have src contains java source files, WEB-INF contains lib, and jsp pages. Do we have any similar standard directory structure in PHP? Also do we have layering in php like we have layers in java (e.g. Web, Service, DAO layers)

我浏览了一些链接。但是每个人给出不同的答案。

I browsed few links. But every one giving different answers.

不确定我们是否可以比较两种语言。我只是想遵守一些标准。

Not sure if we can compare the two languages. I just want to stick to some standards.

预先感谢。

推荐答案

不。 PHP是您所用。可以是非常简单的平面文件,也可以根据需要。

Nope. PHP is what you make of it. It can be very simple flat files, or however you want it.

话虽这么说,但仍有一些商定的编码标准,但没有强制执行说标准。它们被称为PSR(PHP标准建议书)。这里有一个背景: http://net.tutsplus.com/tutorials/ php / psr-huh /

您可以在此处逐一查看标准: http://www.php-fig.org/psr/

That being said, there are a few agreed upon coding standards, but there is no "enforcement" of said standards. They are called PSR (PHP Standards Recommendation). There is a background on it here: http://net.tutsplus.com/tutorials/php/psr-huh/
You can view the standards one by one here: http://www.php-fig.org/psr/

大多数主要框架都遵循这些标准,如果您要使用

Most major frameworks follow these standards, and if you are going to use one, it may be easier to go with the flow.

同样,每个框架,项目,插件,程序等,其布局都不同,项目结构也不同。常见的结构是这样的:

Again, every framework, project, plugin, program, etc, have different layouts with different project structures. A common structure is something like this:

-framework_dir
-public_html
    -js
    -img
    -css
    -index.php
    -protected/private
        -controllers
        -models
        -views
        -etc

然后他们使用 .htaccess 文件阻止访问到受保护的目录。同样,这只是我在几个框架中看到的常见表示形式。如果您正在做一个个人项目,请使用适合您的东西。每个框架都将为您提供不同的库或访问数据的方式。没有层,但是每个框架都具有处理不同区域(电子邮件,数据库,缓存,http,日志等)的对象。因为有数十种流行的语言,所以要由您自己决定是否适合您的哲学或项目。观看5分钟的博客视频中的一些视频,看看有什么好玩的,然后进行几天的测试。如果您不喜欢它,请切换到另一个。

They then use the .htaccess file to block access to the protected directories. Again, this is just the common representation I have seen in several frameworks. If you are doing a personal project, just use something that is comfortable to you. Every framework is going to give you a different library or way to access the data. There are no "layers", but again every framework has objects that handle different areas (email, database, cache, http, logs, etc). Because there are dozens of popular ones, it is just up to you to find what fits with your philosophy or project. Watch a few of the 5 minute blog videos, see what jives, and then give it a test run for a couple days. If you don't like it, switch to another.

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

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