Structure of MVC Folders

Asked

Viewed 4,503 times

6

Hello. I am wanting to build my own application using the MVC standard. I understand the separation of each item(Model, View and Controller). But I want to make some sort of separation between the Front-end and the Back-end, since some backend controllers will have the same name as Frontend’s.

I cannot visualize something that is simpler to create this constraint. Does anyone have any idea how to do?

Estrutura básica do frontend

  • What do you call "front-end controler"? the ones that are used with ajax?

  • 3

    There must be 5 or 6 questions that look like this.

  • 1

    It is not a simple thing to explain, but I believe that the set of classes here https://github.com/szagot/config will help you to work separation, in particular the Uri class (https://github.com/szagot/config#Uri).

  • Sergio, frontend controllers are the PHP manipulations with the database that generate the printable information in the View HTML

  • @Szag-Ot I actually need a physical separation between Frontend and Backend

  • @In this case, just create the "admin" (the q vc is calling the backend) with the same structure, treating the /admin/ (or the name q wish) as a separate system, with its own htaccess (if applicable). Hence just set a folder for crontollers in common.

  • @Szag-Ot Where would I put this admin to replace the backed?

  • @Thiagodavitoriaanunes in the root itself... or anywhere else you prefer. The structure within admin/ would be the same as that of the root folder, but the models crontrollers would be from the administrative, whereas at the root would be from the public access (store, blog, etc...).

  • @Szag-Ot I see. My debt is: I will need Views, Controllers and Model (this can be one, both for frontend and backend/admin) Would I create other controller and view folders within the admin folder? [I’m looking for the smartest way to create these mechanisms]

  • @Thiagodavictorianunes I believe depends a lot on your business rule. But usually the models that govern the rules of business should stay in one place. This should not be a problem if you are following a standard such as PSR-0 or PSR-4 (http://www.php-fig.org/psr/psr-4/). If you want to show the controllers and the views, since these are individual, target them by the controllers, you can also set them all at the root, leaving only the views separately. I’ll see if I can buy you some time so I can create a General Division model for you

  • 1

    @Szag-Ot Right. Thanks man. I’m used to having Frontend and Backend Controllers and Views separate, as well as js, css and other files. I wanted to create a different structure from this one. I appreciate the help.

  • I recommend exploring the generators of Yeoman, for example the Generator-angular-php and Generator-angular-Fullstack.

  • @Brunowego I’ll write it down here. Thank you.

Show 8 more comments

1 answer

6

In my experience, the problem of this structuring always occurs with views, since 50 views can use only 1 controller and 1 model, so my suggestion and how to work with my own framework, is to separate only the views getting more or less like this, based on its structure:

app
   controllers
   models
   views
      admin (Backend)
         produtos
            add_produtos.phtml
            edit_produtos.phtml
            list_produtos.phtml
            del_produtos.phtml
         usuarios
            add_usuarios.phtml
            edit_usuarios.phtml
            list_usuarios.phtml
            del_usuarios.phtml     
      site (Frontend)
            home.phtml
            empresa.phtml
            clientes.phtml
            contato.phtml

Browser other questions tagged

You are not signed in. Login or sign up in order to post.