网站结构和 php 脚本
我目前正在开发 CMS,它将有大量的用户输入,并且我开始考虑我将拥有的所有单独的 PHP 脚本。这正常吗?我可以将所有这些文件缩减为一类吗?
我想这就是我想问的。
- 有没有办法通过整个 PHP 类而不是一个小脚本从表单或 AJAX 请求调用操作或函数?
- 我的资产/脚本(PHP 和 JavaScript)开始积累。这是正常的吗?
这是我第一次尝试 CMS,所以这里完全是新手。
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.
- Is there a way to call actions or functions from a form or AJAX request through an entire PHP class instead a little script?
- My assets/scripts (PHP and JavaScript) are starting to accumulate. Is this normal?
This is my first CMS attempt so total newbcake here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编程基本上有整体式和模块化方法。
整体式,因为您需要的一切都在一个代码块(整体式)中。严格来说,我们现在没有太多机会编写整体代码,因为我们严重依赖库或其他代码片段。
模块化意味着将所有内容分成易于维护和调试的小部分。 PHP 中的所有函数在这方面都已经是模块了。函数和类是模块化方法中的主要对象。
如果您想在自己的项目中继续使用这种方法,您最终也会将对象拆分为单个文件,其中大部分包含类。通过类,我们可以使用自动加载器,甚至不必担心关于不再包含文件。
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.