Question

Hi i seek some help and your experience on the organization of my project. Since this is my first project, I don't know if I am organizing it as I should, this is an e-commerce platform to various sites. My project is current organized this way:

.
├── admin
│   └── index.php (redirects to system/admin/index.php)
├── conf.php (saves info about the server database etc...)
├── index.php
└── system
    ├── admin
    │   ├── add_prd.php
    │   └── index.php(this is the main administration page)
    ├── css
    │   └── css.css
    ├── func.php(this is my functions library witch is included in every file that uses a function made by me)
    ├── img (this is where all pics go)
    │   ├── img_artigos(this is where all pics *of the products* go)
    │   │   ├── product1.png
    │   │   └── ...
    │   └── (system images go here)banner, all other images of the "template", etc...(probably i will make a new folder called system for that)
    ├── logout.php
    ├── order.php
    └── reg.php

and this is how it works, the index have every thing in it, using a switch case when the register is clicked the page is reloaded and via GET receives the instruction to run the function register() that echo's out the registration form, then it is submitted to reg.php(last file in the tree) that inserts the registration on the database and redirects to the index.php. The same is what happens to logout() and order() that redirects just to execute the function and then goes back to index, this pages are there just to use one function and redirect the user to the index page. I even thought in doing the same thing to the redirect, using the switch case to execute the different functions and redirect back to index and the site would have only the index, admin index, redirect, css and func files...

When a user clicks on their name, the page reloads and using GET it instructs the switch case to load the profile_display() function that echoes the profile info...

The same goes to the admin section where the admin user will have the sensation of navigating thought different pages but in fact they never left the index.

What i want to know is if this is correct or if i will have any kind of problem, or if i am using bad practices... if i should go with a more traditional way(many files) and what is going to be better to maintain the traditional or this... and if there is going to be any problems in the server side because of this, and your opinion. thank you in advance.

Was it helpful?

Solution

Although I think your organization is not that bad, its a very basic structure and not that scalable. If your Project is getting bigger, you won't stay that happy.

I would recommend you to have a look at the variety of MVC frameworks out there which do all the routing of your page request and help you to keep your project maintainable. They also help to split logical code and your layout.

If you wan't to stay with that structure you should at least change some parts of it:

I may misunderstand you but you should do it all the same way. Not using functions called from your switch statements and on the same time redirect directly to reg.php in my opinion.

switch($page) {
    case "register":
    //inlude file or call function
    break;
    case "register_submit":
    //inlude file or call function
    break;
    case "logout":
    //inlude file or call function
    break;
    case "order":
    //inlude file or call function
    break;
    case "login":
    //inlude file or call function
    break;
}

Then maybe make an "assets" folder or you can call it whatever you like on the same level as your systems folder and put all your css/js/image files in there.

But I stilly recommend you to use an MVC framework. Personally I'm using Codeigniter. But there are several good frameworks like for example Kohana.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top