Structuring the PHP project – PHP Blog from 0

Share on facebook
Share on twitter
Share on linkedin

If I don’t write any post, I won’t have visitors, it’s a fact so… Hello! I’m Julián Campos and I’m developping a PHP Blog from 0. At this point, I’ll speak you about the folder structure for a PHP project. Specifically, the folder structure that I’ll use for the project.

The last post was setting up Git and Github. These weeks I have a lot of work to do appart the developpment of this project, so this is the reason I’m working slowly in the blog project

This project is my very first serious project that I develop in PHP. I’ve done other projects but the structuture was improvised. This time, I’m thinking about all since the beginning.

Basic structure of PHP folders

So… Let’s go! I didn’t have any idea how start so the first steps was search information. I watched the structure of differents PHP works and they have differents elements in common but, normally, these projects was really complex with a folder structure very big. I’m searching for a simple structure. I want that the blog were simple, with a simple structure and an easy editable structure. So I finally landed on youtube to look for information. I’ve watched some videos and they was very long… So boring.

Finally, with the information, my own ideas and getting inspiration from differents PHP framerworks, I’ve started setting up the basic folder structure. Here you have a three structure of the folders:

- application/
   -- admin/
      --- private/
            ---- config/
            ---- controllers/
            ---- models/
            ---- routers/
            ---- views/
      --- public/
            ---- assets/
                 ----- img/
                 ----- css/
                 ----- js/
  -- private/
     --- config/
     --- controllers/
     --- models/
     --- routers/
     --- views/
  -- public/
     --- assets/
          ---- img/
          ---- css/
          ---- js/

Public Folder – That the user view

The first step it was create the basic folder for the frontend design: css, img, js. These three folders are contained in the public folder because they are files which will be used for the public, they will contains the files to create the frontend desing of the website. I’ll use the folder Assets to contain them.

  • Assets: will contain Css, Js and Img that I’ll use for the frontend. Images used by the post will not be in this folder.
  • Css: folder that contains the css styles which includes the styles of Bootstrap and my own styles.
  • Js: the same but for javascript.
  • img: let me think… maybe for the images? Yes, but the images of the frontend design.

The rest of others public folders will be determined in the future when I think about the necessities of the project.

Private folder – For the logic system

These three (or four) folders was obvious. The interesting think appears with the backend structure (PHP). We will start with the private folder. This folder will contais the files to setting up the proyect but they won’t be readable for the users. I’ll manage them with privilegies, but I think that for the organization is better separate them from the rest of files. The folders contained in the private folder will be: Config, Controllers, Models, Views and Routers. Let’s explain them (with time, I’ll write a post about them. They are interesting):

  • Config: I take this idea from the Laravel and MVC frameworks. This folder will contain all the configuration files. I think I’ll use it to contais the initial configuration files (as SQL statement to setting up the database, images of diagrams…, etc) and files as config.php, with the database information, which will be required as least.
  • Controllers: in controllers folder we will have the hearth of the project, we’ll have all the class and functions of the project.
  • Models: this folder will contais the files of objects that will represent the data of the blog. The model will be modeled on your database table structure and it will interact with the database operations (create, read, update and delete). We’ll write the getters and setters of the objetcts. Ex: post.php will be the model for the representation of a blog post in the database and It will have the getters and setters to obtain the information of the database.
  • Views: The view is responsible to take in the data from the controller and display those values. We’ll have a HTML and PHP file to display the information about the models (calling the getters and setters). If we have a models of post (models/post.php) we will have a view of post (view/post.php).
  • Routers: in this folder I’ll have the system to control the URL system and have nice permalinks for the post. I don’t know how it’s works, so I’ll study this in the future.

Admin Folder – Where we will control the system

Next step is the administration system. In the administration system we will controll the blog, write the post, moderate and view the coments… It’s a really hard task and I think that everytime I could improve it. So the target is complete the basic administration and with time, expand it.

So, the basic structure are the same that public website directory:

  • A public folder with Assets folder (css, js and img).
  • A private folder with Config, Controllers, Models, Views and Routers.

And I think it’s all for today. If you think that I can improve it, I’ll read you in the coments.

See you! 🙂

More to explorer

PHP Blog – A Status Update

Hello! I’m here again! And this time I will speak you about the status of my project “My Own PHP Blog” before

Leave a Reply

Your email address will not be published.