douba8758 2011-07-19 07:46
浏览 23
已采纳

PHP最佳实践:我正在加载$ GLOBALS数组,其中包含许多要在我的php页面之间共享的信息

my question is about whether what I'm doing is proper , or if it causes security / performance issues.

Im using the $GLOBALS array , and filling it with a lot of values from the database, such as (page title, user information, template information ... etc) so that all my php files have access to this info. Im following the MVC design pattern, so this is how my View files have access to the information generated in the Model files.

If this is not the proper way to do things, please tell me why, and what is the proper way.

Thank you

  • 写回答

2条回答 默认 最新

  • doumi7854 2011-07-19 08:03
    关注

    You're is not following the MVC pattern, you are just using global variables to display something in a "shared all"-script in a "shared nothing"-architecture.

    Doing output can mean you get a view of something, but normally that is not to be mixed with the term View of the MVC (Model-View-Controller) pattern. What you do, templating or output is maybe a better wording.

    If this is not the proper way to do things, please tell me why, and what is the proper way.

    If you want to implement MVC pattern, than this might be the MVC you're referring to:

    • Model: Your Filesystem and Database
    • View: Your HTML output + CSS + JS
    • Controller: Your PHP Script

    MVC is just a pattern. You can implement it like you feel good. And you can find it in lot of stuff that has implemented nothing. It's just a pattern.

    But more precisely the MVC pattern is more commonly seen for an object oriented implementation of it. Your implementation is totally different to such of a object oriented one, you're using global state instead of object instances.

    But you have not written in your question that you thought about implementing an object oriented MVC pattern and that templating script you use is part of it.

    It can be perfectly proper to do it like you do it depending on the needs to fulfil.

    MVC is just a pattern. It has pro's and con's. It has benefits and it has consequences. It's just a pattern.

    Especially if you're concerned about performance don't make things more complicated as they need to be, e.g. loading a full blown object tree to just display some variables inside a HTML template.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写