如何用PHP的MVC设计做一个社交网络?

发布于 2024-10-21 17:50:14 字数 1383 浏览 2 评论 0原文

我正在建立一个类似于 Facebook 的社交网络类型网站。我正在使用 PHP、javascript、jquery、MySQL、Memcache 和 APC。我以前用 PHP 构建过社交网络,它们是非常复杂和大型的应用程序(用户系统、论坛、博客、个人资料、虚拟货币、货币商店、消息传递以及更多功能/部分/模块,但全部都是以程序风格编码完成的)在过去的一年里,我一直在研究 PHP 面向对象的 OO,现在我对 PHP 中的 OO 有了更好的理解(非常感谢 Stackoverflow)。之前,我对类和对象以及如何使用或创建它们一无所知。

好吧,回到问题,我将构建自己的框架,或者更好地说,该项目的代码“库”,然后我可以在将来需要时使用它,我不想使用现有框架,我会。更确切地说,我可以真正了解 eac 方法和对象等如何工作

。 、邮件/消息、论坛、博客等...每个模块几乎都会被插入,并且它将与我的其他代码一起使用。因此每个模块都有自己的文件夹并且几乎是独立的。 “modules/forums/”可以有控制器+模型+视图......“modules/forums/controllers/”“modules/forums/models/”“modules/forums/views/”

这是我到目前为止的基本想法,它当一切都说完了之后,我们可以而且很可能会改变一些。

我已经创建了一个 Routing 类,它将接受 URI 的数组映射来进行匹配。如果我去的话结果示例
www.domain.com/forums/viewtopic/id-242342/page-23

然后我会有一个与正则表达式匹配的数组,它会给我这样的东西......

$uri['module'] = 'forums';  
$uri['method'] = 'viewtopic';  
$uri['id'] = '242342';  
$uri['paging'] = '23'; 

然后我可以使用该数组为该页面构建或调用适当的内容。

我正在考虑使用一个简单的模板/视图类来包含一个视图文件,该文件将混合 html 和 PHP,但除了 if/else、foreach、变量等之外没有真正的 logig,

这是我真正的问题或我没有完全理解的地方。 ..这种 MVC 类型模式似乎非常适合简单的页面,例如博客,我可以使用 MVC 来显示博客文章或博客列表,但是像您在 facebook、博客等网站中看到的更复杂的页面页面,可能不仅仅是博客内容,它可能有广告块、朋友块等以及页面上的其他内容,对于这样的网站使用 MVC 和视图/模板是一个坏主意吗?我注意到包括 facebook 在内的所有社交网站,似乎没有一个使用该系统,它们都有单独的页面来构建页面,例如,邮件/消息将位于 messages.php 上,而不是通过 1 个文件路由的所有内容。

我希望这个问题/帖子对某人有意义,并且有人可以提供一些见解,感谢您的时间和任何建议/提示/建议!

I am building a social network type site similar to Facebook. I am using PHP, javascript, jquery, MySQL, Memcache, and APC. I previously have built social networks with PHP and they were very complex and large applications (user system, forums, blogs, profiles, virtual currency, store for currency, messaging, and lots more features/sections/modules but all done in procedural style coding, I have spent the past year researching PHP object oriented OO and I now have a much better understanding of OO in PHP ( many thanks to Stackoverflow ). Before, I knew nothing at all about classes and objects or how to use or create them.

Ok so back to the question, I am going to build my own framework or better said, "Library" of code for this project and then I can use it in the future if needed. I do not want to use existing framework, I would much rather build my own so I can really learn how eac method and object, etc.. are working.

I am leaning towards using the MVC pattern or something very similar. I will have what I will call Modules. example modules; Users or account, mail/messaging, forums, blogs, etc.... each Module will pretty much be drop in and it will work with my other code. So each module will have it's own folder and be pretty much self contained. "modules/forums/" could have controllers + models + views.... "modules/forums/controllers/" "modules/forums/models/" "modules/forums/views/"

That is my basic IDEA so far, it can and will probably change some when it's all said and done.

I have already created a Routing class that will take in an Array Map of URI to match. Example result if I went to
www.domain.com/forums/viewtopic/id-242342/page-23

Then I I would have an array matched with regex that would give me something like this...

$uri['module'] = 'forums';  
$uri['method'] = 'viewtopic';  
$uri['id'] = '242342';  
$uri['paging'] = '23'; 

I can then use that array to build or call the appropriate stuff for that page.

I am thinking about using a simple template/view class to include a view file that will have html and PHP mixed but with no real logig besides if/else, foreach, variables, etc

Where my real question or where I am not understanding fully...This MVC type pattern seems to work great for simple pages, for example a blog, I could have MVC to show a blog post or list of blogs, but a more complex page like you would seen in a site like facebook, a blog page, might be more then just blog stuff, it may have advertisment block, friends block, etc and other stuff on a page, is it a bad idea to use MVC and views/templates for a site like that? I notice all the social network sites including facebook, not one of them seems to use this system, they all have seperate pages to build the page, example, mail/messages will be on messages.php instead of everything routed through 1 file.

I hope this question/post makes sense to someone and someone can offer some insight, thanks for your time and any suggestions/tips/advice!

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

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

发布评论

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

评论(1

愁杀 2024-10-28 17:50:14

我会使用现有的框架,但是如果您坚持创建自己的框架,请查看此 关于如何编写自己的 PHP MVC 框架的文章。它内容丰富,向您展示了如何克服与此类任务相关的一些挑战的内在原理。

至于 MVC 作为复杂网页设计模式的强大功能,Stackoverflow 使用 ASP.NET MVC 3 作为其 WebFramework (参考)。纳夫说道。

I would use an existing framework, however if you're insistent on creating your own, have at look at this article about how to write your own PHP MVC framework. It's very informative and shows you the inners of how to overcome some of the challenges assosiated with such a task.

As for the power and capability of MVC as a design pattern for complex webpages, Stackoverflow uses ASP.NET MVC 3 as it's WebFramework (ref). Nuff said.

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