MVC PHP - Libraries - Directory Structure

1

I have a question regarding the folder structure of the application.

Next, the question arises when there is a need to write a class that integrates with an API that class would be allocated in which part? For example, this class would not have behavior of a component (it does not have any kind of business logic) but maybe of a lib (Library) that would be an interface to consume API resources. p>

Imagine the following structure:

/app/
 - controllers/
 - components/
 - models/
 - vendors/

But the question is, if API is a package written by me, it should not go to vendors (since vendors are only for third party packages), I am right? Or maybe it would be ideal to have a new librarys / directory for the application's internal packages?

    
asked by anonymous 30.04.2015 / 16:19

2 answers

1

In cases like this the organization is done as follows: /vendors/Company/Library/Company/PackageName . If your code is generic and can be reused in other projects without much need of adaptation, that is, as you said yourself, if you do not have any business rules, its place is vendors .

    
30.04.2015 / 16:27
0

My answer goes in the direction of my experience in MVC and specifically in PHP as posed in the question and in regards to its structure.

Without entering into basic concepts, experience has taken me over the years to adopt a structure different from the one it presents, however I know well that it depends a lot on a case-by-case basis. For a project that also implements an api together:

/projecto/
   |--api/
   |    |--resources/
   |    |index.php
   |    |.htaccess
   |
   |--application/
   |    |--config/
   |    |--controllers/
   |    |--models/
   |    |--libraries/
   |    |--views/
   |    |--(etc... dentro da lógica)
   |    |.htaccess (deny from all)
   | 
   |--public/
   |--vendor/
   |
   |index.php
   |.htaccess

As you can see, models is inside application and not components I think it will be equivalent to libraries and as for vendors the norm is to call it vendor in the singular case work with Composer ... it fits.

The .htaccess is placed in every directory that is at the root of the project, and here comes my direct answer to your question about API . As an additional service to the project, I usually include the directory API na raíz and with that .htaccess , in this way it defends the resources present by means of a friendly url .

I remember that an MVC separates the layout of the PHP code and in regards to the API should separate the implementation of resources from the logic of models that for code maintenance issues should use implementations in application/models , in this case: )

    
30.04.2015 / 18:42