Site structure and php scripts [closed]

风流意气都作罢 提交于 2019-12-13 09:36:07

问题


I am working on a CMS currently and it's going to have a fair amount of user input and I am starting to think about all the separate PHP scripts I am going to have. Is that normal? Can I shrink all these files down into one class?

I guess here's what I am trying to ask.

  1. Is there a way to call actions or functions from a form or AJAX request through an entire PHP class instead a little script?
  2. My assets/scripts (PHP and JavaScript) are starting to accumulate. Is this normal?

This is my first CMS attempt so total newbcake here.


回答1:


There is basically a monolithic and a modular approach in programming.

Monolithic as in everything you need is in one block (monolith) of code. Strictly speaking we don't have many chances left to write monolithic code today as we depend heavily on libraries or other pieces of code.

Modular means to split everything in little pieces which are easy to maintain and debug. All the functions in PHP are already modules in that regard. Functions and classes are the main objects in a modular approach.

If you like to stay with this approach in your own projects you will eventually also split your objects into single files, mostly with classes. With classes we can us the autoloader and don't even have to worry about including the files anymore.



来源:https://stackoverflow.com/questions/6943855/site-structure-and-php-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!