Question

I'm confused with this these days. I have some principles for myself:

  1. I don't use session in model.(some Dependency Injection technique may help)

  2. I think libraries are like tools. It shouldn't has dependency on applications or frameworks.

  3. Base on 2., I think shouldn't use session in library.

  4. Do not put business logic in controller

Then the problem appears: Some features need session. Like 'user login', 'shopping cart' and etc. How should I use 'session' if I don't wanna it appear in 'model' and 'library'?

I think the traditional 'MVC' conception in web frameworks is not clear enough for this.

Usually there are folders like 'model', 'controller', 'view', 'library', 'helper' to accomplish 'MVC'. But there's no position for 'service layer'.

I think up with two solutions, but they are still not perfect.

First solution: implement service layer in model and library(if it needs session).

For example, in Codeigniter, the most popular open source for authentication is Ben Edmunds' Ion Auth. It implements the 'login' feature with 'library' and 'model'. But I think it's weird. I think the 'service layer' should only rely on library, not to be the library itself.

Second solution: separate models to 'service model' and 'data access model'.

Both models can access database, and only use session in service model. Maybe data access model can implement most of the low level features for service model to use. But in this way, it break the principle 'do not use session in model'.

So, I think the 'model' concept in 'MVC' is confusing and dangerous. where is the service layer in MVC ??

or maybe I should ask this question in other words:

What exactly is model in MVC?

I would be very appreciate for any suggestions and ideas :D Thank you very much.

Was it helpful?

Solution

This question is similar to :

How should a model be structured in MVC?

and What is MVC (Model View Controller)?

You might get solution you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top