I study php OOP a couple of weeks, made the structure of MVC with a router.

https://github.com/versinsk/mymvc

Are there any vulnerabilities in this site and how well / poorly written is the code? He took many routers as a basis, paid attention to the strict verification of the name of the controller and method with an array of templates.

Ps Waiting for any criticism, for me it is very important.

  • There is only a skeleton. Write a website of average complexity and then you will understand the minuses yourself - ArchDemon

1 answer 1

  1. You have a model of this property of the controller. And if you need to work with several models in one action game? Why a factory, besides, in the controller you refer to the static by name.
  2. Namespaces and Autoloader classes. (By the way, the naming of classes would be reduced to one standard. And then somewhere with a little somewhere with a big one)
  3. The router is not dynamic. Suppose you need to add a new action. You create it in the controller and then you also register it in the components / router folder (which is also somehow unclear, it can be renamed to the config, otherwise it is not a component)
  4. I would get rid of ROOT. Besides, I see no reason to declare it at index

Well, in general, there is not much to look at.

Imagine just how you will do.

  • Separation of roles
  • Connect other components
  • Transfer your MVC to another project, server, folder
  • If the parameters in the action will be in random order
  • If you have modules (with nested MVC), from the 1000th action
  • If someone adapts your MVC to your needs, without editing your code.
  • Different formats Resoponse (json, html)
  • If MVC is a body kit over some already finished system, and if the routing did not work, the code should continue to be executed further.
  • Event like beforeAction, afterAction
  • How will the model work with the database component?
  • Thanks, I will consider, at the expense of a dynamic router, I specifically created an array of templates to search for pre-prepared templates. Then you can simply delete the template, thus turn off some page, and not delete the action that may be needed later. - versinsk