duankeng1911 2011-03-09 23:36
浏览 62
已采纳

如何在PHP中使用MVC设计构建社交网络?

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!

  • 写回答

1条回答 默认 最新

  • dougou8458 2011-03-10 00:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来