Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call function A inside function B on Codeigniter's controller

I have a controller that have about 5-6 functions.

class Register extends CI_Controller {
public function index()
{
  //  some code written
}    
public function Add()
{
  //  Some code written
}
public function xyz()
{
  //  Some code written
  $this->abc();
}
public function abc()
{
  // Some code written
}
}

In xyz function, i want to call abc function. Is this possible ? if so, how to call it ?

like image 833
Vaibhav Singhal Avatar asked Oct 31 '13 08:10

Vaibhav Singhal


People also ask

How pass data from one function to another in CodeIgniter?

class Send_value extends CI_Controller { public function main_page() { $data['user'] = $this->input->post('fullName'); ... } public function welcome_page(){ //Now I would like to pass $data['user'] here. } }

What is $this in CodeIgniter?

In terms of codeigniter: You'll notice that each controller in codeigniter extends the base controller class. Using $this in a controller gives you access to everything which is defined in your controller, as well as what's inherited from the base controller.


1 Answers

It is possible, the code you have written is correct

public function xyz()
{
  //  Some code written
  $this->abc();     //This will call abc()
}

EDIT:

Have you properly tried this?

class Register extends CI_Controller {
    public function xyz()
    {
      $this->abc();
    }
    public function abc()
    {
      echo "I am running!!!";
    }
}

and call register/xyz

like image 124
Saravanan Avatar answered Oct 17 '22 12:10

Saravanan