SRP and MVC use?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


As you might have guessed I have a problem concerning the SRP
principle of OOP. I'm trying to build my own framework (just for the
sake of learning and maybe using it for my own website), I would like
to keep it simple but effective. For this I use the MVC pattern.

My classes work well, but it isn't perfectly yet. I do use single
entry (.htaccess -> index.php) after which the router does reroute it
to the proper controller.

I have seperated the view and controller quite well, but I think my
controller isn't really perfect yet.

Now I wonder if there is anyone that can help me by showing how to use
the SRP principle properly.

What I have now (my user class) looks simplified like this:

if the uri is like this:

The user class gets loaded, the constructor sees there is an action
and sets it in a variable within the object. The method index() is
called. And this handles the action:

// this is in the index() within a switch($action)
case 'login':
         if($_SESSION['signed_in'] == 0){
               $data = $this->get_data('login');
               $checked_data = $this->check_input('login',$data);

               if($checked_data === TRUE){
                     header('location: ' . $this->register-
Quoted text here. Click to load it
Quoted text here. Click to load it
                  // login data incorrect, log login-try to database
to be able to block ip adressess
case 'logout':
case 'create':
// etc.
case 'edit':
// etc.
case 'delete':



As you can see the user class handles the actions, however after
reading about SRP I see that this is not exactly perfect. Apparently
it is better for the user class to contain the user data and give it
back using methods like getUserName() or isLoggedIn().

In my controller I also have all the SQL which should be in a model,
according th what I read.

Now I wonder where do I actually handle all those actions like
login(), create(), edit(), etc.? I think this should be another class
but I don't really know how to do this perfectly by "seperation of

Anywone who can explain me how this is done (or maybe show me a


Site Timeline