Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:55:09+00:00 2026-05-24T01:55:09+00:00

What is the best practices as far as storing variables in the Controller or

  • 0

What is the best practices as far as storing variables in the Controller or Model?
For instance when the script is executed. it grabs the user id from the session and gets what type of user it is, Super Admin, Admin, Service Rep, Sales Rep. We also check to see what account the user id belongs too, and grab all the setting for that account.

My questions is where do i store these values, in the controller or model?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:55:09+00:00Added an answer on May 24, 2026 at 1:55 am

    In PHP, it is a little strange to think about a true MVC model, because your model, view, and controller can access the $_SESSION.

    If, for example, you are going to log a user in, your model would do the following:

    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');
        }
    }
    

    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.


    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?

    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.

    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:

    1. Request is made to controller
    2. Controller gets information form model
      (this is optional, maybe the controller doesn’t need anything from the model)
    3. Model returns information to controller
      (Happens if you made a request form the previous step)
    4. Controller passes appropriate information to view.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Far as best practices are concerned, which is better: public void SomeMethod(string str) {
I have a question about best practices regarding how one should approach storing complex
I've been doing a lot of research to determine best practices for storing passwords
Can anyone provide a best-practices example for where to store user preferences for a
Hoping there's been a best practices way to accomplish this so far. Basically, I'm
I'm trying to ascertain best-practices for shared code amongst Git repositories. So far, I've
Best practices or tools for installing a SQL Server database I have a SQL
What best practices should be observed when implementing HDL code? What are the commonalities
Yahoo best practices states that putting JavaScript files on bottom might make your pages
What best practices have you used in unit testing embedded software that are peculiar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.