How do I create a PHP project?

I am about to start another major PHP project. This time I intend the project folder to be neat! Therefore, I have a few questions regarding the preservation of my project and DRY:

  • How can I distinguish between PHP source files and PHP files that the browser should access? In other words, how can I understand which PHP files give output and give definitions of functions or classes?

  • I plan to separate my PHP functions from static classes separated by subject, like database :: create () or editor :: write (). What do you think about this?

  • I plan to create a PHP file "core.php" that will be included at the beginning of each PHP SINGLE file in the project. This file will handle authentication and include basic features. Thoughts?

  • The project will be heavily based on Ajax. This asks the question: should my PHP functions be valid PHP functions or should they be separate PHP files that take GET or POST? My plan does how . I create a folder for the PHP source files and one for the PHP “ajax” files (or something else), and the second folder is filled with the file names with the functions that they will execute. Then the PHP file simply contains a function call and an output entry for Ajax. Thoughts?

Any other comments or tips before I start this project will be great!


Edit

Perhaps I could not emphasize how much Ajax founded this web application. Codeigniter seems like a great tool for creating web pages or simple web applications like a blog. My application will be a little different. Like uTorrent WebUI, my web application will be static on one page if Ajax does all the work under the hood. It seems a little awkward to use Codeigniter for such a project.

Is there any other architecture created with this kind of application?

+6
javascript ajax php structure project
source share
4 answers

Do you consider using a framework like Codeigniter? Are you familiar with any design patterns like MVC? Both of these will help dictate the location of files and the separation of logic in your project.

EDIT: Codeigniter uses MVC, which is just a great template for web programming. Check out these two videos that they have for study guides. Only about 30 minutes combined, and, of course, full of good knowledge, both in order to look at how their wireframe works and the insight offered by their folder structure.

EDIT2: http://codeigniter.com/tutorials

+3
source share

If you expect this to be a major project, I would highly recommend using one of the many installed frameworks already existing as Symfony or Zend. You would:

  • drastically reduce the amount of code you need to write
  • avoid errors in your components.
  • learning best practices

But if you insist on doing it yourself.

I plan to create a PHP file "core.php" that will be included at the beginning of each PHP SINGLE file in the project. This file will handle authentication and include basic features. Thoughts?

I cannot stress enough, "do not do this." There is a rule among experienced PHP developers that any project with a large core.php file that is a warning sign of poor development should be avoided.

Secondly, there is no need to reinvent the wheel when it comes to an abstract database; look at the MDB2 or Doctrine pear designs.

A large number of static classes is also a sign of poorly conceived development. Static classes should be used sparingly because they are difficult to verify and often not necessary.

+3
source share

Why not have one index.php that handles all the execution, and then has a .htaccess file that will direct the URLs to the correct location. This means that you can log in and verify it in a single file.

You may have a condition at the top of your entire other file so that they cannot be directly accessed, for example:

<?php if(FROM_INDEX!="true") die("<b>ACCESS_ERROR</b><br /><br />Please use the main page instead of accessing this file directly."); 

I also recommend Codeigniter, as it has many features like this already, and will significantly speed up your development time.

+1
source share

I'm not sure how complicated the system you are looking for. But recently, I found a small structure that works with a URL. https://github.com/ivorychicken/sammy

If you do not mind to play with him, you could use it as a starting point and build it.

0
source share

All Articles