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 6126869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:25:53+00:00 2026-05-23T16:25:53+00:00

I want to pass a user id value in variable $userID, to a function

  • 0

I want to pass a user id value in variable $userID, to a function in a Model class Clientmodel. The function is get_username(), now in a model do I have to define that function to accept a variable as a parameter? so.. get_username($userID)? Just want to know how is the recommended way in code igniter?

Thanks!

tariq

  • 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-23T16:25:54+00:00Added an answer on May 23, 2026 at 4:25 pm

    That really depends on what you use the model for. Most of the time, it will make sense to have a parameter to the method and use that every time:

    // Model
    function get_username($userID)
    {
        // do something with $userID
    }
    
    // Controller
    $this->some_model->get_username($some_id);
    

    On the other hand, sometimes it makes sense for the Model to be “stateful” — do you have one userID per controller? Will it ever be more than one? Do you need the userID in a large number of methods of that model? Then maybe this will make sense instead:

    // Model
    function set_userid($userID)
    {
        $this->userID = $userID;
    }
    
    function get_username()
    {
        // do something with $this->userID
    }
    
    // Controller
    $this->some_model->set_userid( $some_id );
    $this->some_model->get_username();
    

    Other times, you may have one userID which you plan on using over and over, but sometimes you need to use another value, that is when default arguments come into play:

    // Model
    function set_userid($userID)
    {
        $this->userID = $userID;
    }
    
    function get_username( $userID = NULL )
    {
        if( $userID === NULL ) $userID = $this->userID;
        // do something with $userID (not $this->userID)
    }
    
    
    // Controller
    $this->some_model->set_userid( $some_id );
    $this->some_model->get_username();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this function pymssql.connect(host=my host,user=my user,password=my pass,database=mydb) I want to read the user
I want to pass a variable set by the user to the setcookie function.
I want to pass an integer value to a form in .Net so that
I want to pass in the tType of a class to a function, and
I want pass a value to ssis package, but i have an error back
I wrote a class that lets me pass in a list of variable types,
I have never done any Singleton class before and now I figured that for
Let´s say I a have an User class and I want to return all
I have a class Database and Class User . My problem is that I
I want to pass an enum value as command parameter in WPF, using something

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.