Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In PHP, it is a little strange to think about a true MVC model, because your model, view, and controller can access the $_SESSION.</p> <p>If, for example, you are going to log a user in, your model would do the following:</p> <pre><code>class Model{ ... static function login($username, $password){ $result = Model::getUser($username, $password); if(empty($result)){ return false; } else { $_SESSION['userid'] = $result['id']; // Assign other information you think you'll need in the session here } } static function loggedIn(){ if(isset($_SESSION['userid']){ return true; } else { return false; } } static function getAttribute($attr){ return $_SESSION[$attr]; } ... } class Controller{ function someFxn(){ $userInfo = Model::getAttribute('someAttr'); } } </code></pre> <p>Obviously this code has to be expended upon, but it should display the concepts correctly. I also used static functions in the model, but you can make the model an object. <br/> <hr></p> <blockquote> <p>My questions is where do i store these settings, in the Model, or pass it back to the controller, and the controller will store these settings?</p> </blockquote> <p>Depending on how you want to do it, you either fetch the settings every time form the database through the model or you can store them in the session. Storing things in the $_SESSION will allow you to have less database calls. In practice, the model manipulates the $_SESSION or the database. If your model is particular to something (you could make your own user model), then you instantiate that object and store your information in private members. </p> <p>The point of the controller is to take information form the model and then render your page accordingly. Really a MVC dataflow works this way:</p> <ol> <li>Request is made to controller</li> <li>Controller gets information form model<br> (this is optional, maybe the controller doesn't need anything from the model)</li> <li>Model returns information to controller<br> (Happens if you made a request form the previous step)</li> <li>Controller passes appropriate information to view.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload