Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter';上的函数B内调用函数A;s控制器_Php_Codeigniter - Fatal编程技术网

Php 在Codeigniter';上的函数B内调用函数A;s控制器

Php 在Codeigniter';上的函数B内调用函数A;s控制器,php,codeigniter,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 ab

我有一个控制器,大约有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
}
}
xyz
函数中,我想调用
abc
函数。
这可能吗?如果是,如何调用它?

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

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

你试过这个了吗

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

然后调用
register/xyz

为什么您认为这是不可能的?你试过了吗?是的,我试过这段代码,但没有运行。是否可以将另一个控制器的函数调用到不同的控制器@Saravanan@always-a-learner,你可以参考这个问题。作为最佳实践,如果两个控制器都要访问一个公共代码,请将其移动到库中,然后从每个控制器访问库。