建议用 PHP 来组织这个?

发布于 2024-10-03 07:47:36 字数 368 浏览 0 评论 0原文

我正在为客户开发一个 CMS,他只能使用密码访问它。 在这个网站上他可以编辑、删除、创建新文章。 我使用这个系统:

  • 由“动作文件”调用的类而不是处理数据,处理并输出它们
  • 打印从类接收的html代码的php文件

问题在于“动作”文件。对于操作文件,我的意思是接收表单数据和请求并将它们发送到类进行处理的文件。上次我用一个开关创建了一个文件,例如“delete_article”、“create_article”等,并使用相对方法进行调用,但这很容易变得一团糟。我想知道是否有最简单的方法来组织这个。也许只是为我想做的每个“动作”做 php 文件?

请考虑到我刚刚开始接触 OOP,所以我可能会说很多愚蠢的事情:D

I'm developing a CMS for a client where he can only access it with a password.
In this site he can edit, delete, create new articles.
I use this system:

  • classes called by the "action files" than handle data, process and output them
  • php files that print the html code received from the classes

The problem is that with the "action" files. for action files I mean the files that receive the forms data and requests and send them to the classes to handle. Last time I made a single file with a switch with for example "delete_article", "create_article" etc with the relative method to call but this becomes easily a MESS. I was wondering if there could be simplest ways to organize this. Maybe just doing php file for every "action" I wanna do?

Please considering I'm just starting with OOP so I could have said a lot stupid things :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑶笙 2024-10-10 07:47:36

如果您刚刚开始接触 OOP,您可以考虑使用 Codeigniter 等框架。优秀的 OOP 的学习曲线很陡峭,但 Codeigniter 的学习曲线则不然。您可以立即开始工作,并在此过程中学到很多有用的最佳实践。例如 MVC 模式,这就是您在使用 OOP 时想要使用的模式。前往 codeigniter.com 并查看!

该手册可在 http://codeigniter.com/user_guide/ 获取

。问题,我建议你仔细看看 MVC,这是一种组织文件的方式。但我知道一开始这可能很难理解,这就是为什么我告诉人们通过使用他们选择的框架来介绍自己。当然,从开发的角度来看,拥有一个框架也是更好的选择,因为它会加快你的进程。

正如 Razor 在评论中所说,重新发明轮子可能是浪费时间。那么,您还会高兴地注意到,有大量用特定框架编写的开源代码,如果您了解这些框架,您将能够非常轻松地扩展这些代码。如果您尝试扩展随机的 CMS 脚本,如果您无法理解它,这很可能也是浪费时间。

You may consider using a framework such as Codeigniter if you are just starting with OOP. The learning curve for good OOP is steep, but the learning curve to Codeigniter is not. You can start work immediately and will learn a lot of useful best practices on the way. Such as the MVC pattern, which is what you want to use when working with OOP. Head over to codeigniter.com and check it out!

The manual is available at http://codeigniter.com/user_guide/

If I was to go straight at answering your question, I would suggest you have a closer look at MVC which is a way of organizing files. But I know that this may be hard to understand in the beginning, which is why I tell people to introduce themselves to it by using a framework of their choice. Of course, from a development perspective having a framework is also preferable because it will speed up your process.

Like Razor said in his comment, reinventing the wheel may be a waste of time. You'll also be happy to note, then, that there is plenty of open-source code written in specific frameworks and if you know these frameworks, you will be able to extend on that code very easily. If you try to extend upon a random CMS-script, this may very well be a waste of time as well if you can't understand it.

尸血腥色 2024-10-10 07:47:36

您应该考虑看看 MVC。即使您是 OOP 初学者,理解这个想法也不难。

真正对您有帮助的是它在 PHP 中的 (MVC) 实现。

一些非常好的教程:

http: //anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

http://php-html.net/tutorials/model-view-controller-in-php/

http://www.phpro.org/tutorials/Model-View-Controller-MVC.html

在 MVC 的背景下,您最终会想出将所有创建、删除和插入功能组织到控制器中的不同方法(操作)中。

You should consider take a look at the MVC. Even if you are OOP beginner it should be not so difficult to understand the idea.

And what would really help you is its (MVC) implementations in PHP.

Some very good tutorials about:

http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

http://php-html.net/tutorials/model-view-controller-in-php/

http://www.phpro.org/tutorials/Model-View-Controller-MVC.html

And speaking in the context of MVC you will eventually come up with organizing all of your create, delete and insert functionality into a different methods (actions) in your controllers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文