vaibhav vaibhav - 2 years ago 155
PHP Question

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 ?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download