OOP, MVC and accessing Session Data

Discussion in 'PHP' started by chopsticks, Jul 27, 2007.

  1. #1
    Hi,

    Recently I have been rebuilding one of my applications in PHP using the MVC (module view controller) Design Pattern. The design seems to work really well and the code is really clean but i'm not exactly sure where I should be accessing session data from. I've read that the model should not have direct access to it, instead the controller will just pass the specific value to wherever it needs to be accessed within the model.

    Anyone care to give examples of how they deal with Session data in the MVC based Applications?

    One can always read and has read but others opinions would be nice right now...

    Thanks -- :)
     
    chopsticks, Jul 27, 2007 IP
  2. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I haven't played with MVC in PHP but in Java I would have the Controller populate the Model with all data that it requires. You can pass the session data just like any other data you would pass from the Controller to the Model.

    $ctrl->setSomeValue($_SESSION['someValue']); // nothing wrong with that
     
    mrmonster, Jul 27, 2007 IP