What is the purpose of “Get Instance” in Codeigniter?
How would you explain this to a total beginner?
What is the purpose of Get Instance in Codeigniter? How would you explain this
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Ok, so everything in CodeIgniter runs through the super-magic
$thisvariable. This only works for classes, as$thisbasically defines the current class.Your controller is a class, so $this is there, allowing you to do
$this->load->model('whatever');In models, you are also using a class. It is slightly different here, as
$thisonly contains useful stuff as you are extending from Model. Still,$thisis still valid.When you are using a helper or a library, you need to find that “instance” or
$thisequivalent.…makes
$cicontain the exact same stuff/code/usefulness as$this, even though you are not in a class, or not in a class that inherits it.That’s an explanation for total beginners after 2 pints, so it’s either wrong or about right. 😉