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

  • Home
  • SEARCH
  • 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 6335047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:46:46+00:00 2026-05-24T18:46:46+00:00

did can be defined a variable for multi function(in codeigniter)? how is it? because

  • 0

did can be defined a variable for multi function(in codeigniter)? how is it?

because i must use of a value similar in multi function.

like:

  class Home extends CI_Controller {
   $hi = 'hello'
    function one() {
       echo $hi;
    }
    function tow() {
       echo $hi;
    }
  }
  • 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-24T18:46:48+00:00Added an answer on May 24, 2026 at 6:46 pm

    what about doing something like this

    class Home extends CI_Controller {
        protected $_hi = 'hi';
        function one() {
           echo $this->_hi;
        }
        function tow() {
           echo $this->_hi;
        }
      }
    

    if the hi is a constant you have better to use the const keyword

      class Home extends CI_Controller {
        const HI = 'hi';
        function one() {
           echo self::HI;
        }
        function tow() {
           echo self::HI;
        }
      }
    

    last point if that constant is used in more than one controller you have better to create a separate class and define the constant in that class.

      class Home extends CI_Controller {
        protected $_find;
    
        function __construct() {
            parent::__construct();
            $this->_find = $this->input->post('find');
        }
    
        function one() {
           echo $this->_find;
        }
        function tow() {
           echo $this->_find;
        }
      }
    

    one remark with the last code snipet, I am not an codeigniter expert so not sure if you can do $this->input->post('find') would work in the constructor

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did select the executable correctly, because I can get it to respond to
I am trying to define a variable in a class that then can be
I need to edit a variable (array) that is defined outside of the function,
How can I test my site in AOL without installing AOL? I did that
I did this in the past, and can't remember the correct command (I think
HI i did this code with help of Marc Gravell in Why can't I
How can I create a const boost matrix? The following did not work: const
What did I do :)? In rails form has f.error_messages alwais empty. How can
I always believe they did, but seeing some answers here make me doubt... Can
The following unicode and string can exist on their own if defined explicitly: >>>

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.