What is the best way to clean the structure of PHP sites without using a framework?

I work on a medium sized PHP site. I am writing "provider" classes for my objects. Basically, if I have a "user" object, I have a "user-provider" class that can query / store users in the database, receive and return user objects. I just include the providers and dependent objects in the files I need.

I am wondering if this is an easy way to structure a PHP site without a framework, so I am interested in hearing from others that the best way to structure a PHP site is not using a framework.

+3
source share
4 answers

First of all, there is nothing wrong with using the framework if it does not introduce unnecessary complexity and / or performance penalties for small applications. In PHP, Symfony and Laravel schemes are pretty good in this regard.

Having said that, if you really do not want a “foreign” structure, you still write your own. So it’s better to plan this. Just grab your favorite framework and structure your project exactly as you would when using this framework . Then write the glue code (i.e., your own mini-frame) yourself. If you notice that your project is growing more than expected, you will not have problems with the transition to a "real" structure.

, -, , , . , , , CSS, ..! .

+3

PHP:

  • myproject/
    • application/
      • configs/
        • ...
      • controllers/
        • ...
      • views/
        • ...
      • models/
        • ...
      • ...
    • library/
      • PEAR/
      • Zend/
      • ...
    • public/ & larr;
      • index.php
      • library/
        • editarea/
        • jquery/
        • OpenLayers/
        • ...
      • media/
        • ...
      • styles/
        • default.css
        • ...
      • ...

Zend, , , .

, , .

:

  • - public/, PHP, Python, Ruby ..
  • . (library/ js/, styles/ css/)
  • . , , , library styles. , , MVC , , templates/, views/.
+1

: http://www.phpguru.org/static/ApplicationStructure

$_PATHS["base"]      = dirname(dirname(__FILE__)) . "/";
$_PATHS["includes"]  = $_PATHS["base"] . "includes/";
$_PATHS["templates"] = $_PATHS["base"] . "templates/";
$_PATHS["pear"]      = $_PATHS["base"] . "pear/";
$_PATHS["logs"]      = $_PATHS["base"] . "logs/";

, ... :)

0

Source: https://habr.com/ru/post/1758968/


All Articles