php通过函数将会话信息传递给模型,允许模型获取会话数据的实例并获得所需内容
问题描述:
does anyone know what the php best practices on session information is? should the model request access to the global session variable and then select the information it needs, or should the methods of the model accept the session information as parameters and let the controller handle grabbing the data from the session?
有谁知道会话信息的php最佳做法是什么? 如果模型请求访问全局会话变量然后选择它需要的信息,或者模型的方法是否应该接受会话信息作为参数并让控制器处理从会话中获取数据? p>
答
Since models contain your business logic, they should be as independent as possible from anything else. E.g. you might want to access your business logic in a context without sessions, from the command line for example.
As such, models should explicitly be passed any and all data they need to work on.