在Codeigniter控制器上的函数B内调用函数A.

Vai*_*hal 17 php codeigniter

我有一个约5-6个功能的控制器.

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
}
}
Run Code Online (Sandbox Code Playgroud)

xyz功能上,我想调用abc函数.这可能吗 ?如果是这样,怎么称呼它?

Sar*_*nan 37

有可能,您编写的代码是正确的

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

编辑:

你有没有试过这个?

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

并打电话 register/xyz