Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project structure for PHP

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.

Thanks in advance.

like image 689
javafan Avatar asked Oct 29 '13 02:10

javafan


People also ask

What is PHP file structure?

1.2. Structure of a PHP Script. PHP is an embedded scripting language when used in Web pages. This means that PHP code is embedded in HTML code. You use HTML tags to enclose the PHP language that you embed in your HTML file — the same way that you would use other HTML tags.

Where should I store PHP files?

You can store the files , anywhere you want, just point the DocumentRoot to the correct location in httpd. conf file. How are functions from other PHP files included/accessible/callable in PHP without explicitly using include or require in each file?

What is directory in laravel?

The database directory contains your database files. public. The public directory helps start your Laravel project and maintains other necessary files such as JavaScript, CSS, and images of your project. resources. The resources directory holds all the Sass files, language (localization) files, and templates (if any).


1 Answers

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

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 

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.

like image 54
Tim Withers Avatar answered Oct 03 '22 15:10

Tim Withers