无法在codeigniter 3.1上调用另一个类的函数

时间:2018-05-28 07:47:13

标签: codeigniter oop

我有两个控制器类  A. datatraining.php  B. chisquare.php

当我从chisquare控制器调用函数并运行datatraining控制器时,我收到如下错误消息: enter image description here

class datatraining extends CI_Controller {

public function progress(){

            $path= __DIR__;
            $new_path= dirname($path,2);

            require_once(APPPATH.'controllers/chisquare.php'); //include controller
            $chisquare = new chisquare();  
            $chisquare->processnaivebayes();

}

class chisquare extends CI_Controller {
public function processnaivebayes(){
        ........
  }
}

任何人都可以帮忙解决这个问题吗?

3 个答案:

答案 0 :(得分:0)

class chisquare extends datatraining {
public function processnaivebayes(){
    ........
 }
}

尝试用第一堂课扩展第二堂课。

答案 1 :(得分:0)

如果你想从datatraining类调用processnaivebayes()函数,你应该扩展chisquare:

class datatraining extends chisquare {
public function progress(){

            $path= __DIR__;
            $new_path= dirname($path,2);

            require_once(APPPATH.'controllers/chisquare.php'); //include controller
            $chisquare = new chisquare();  
            $chisquare->processnaivebayes();

}

class chisquare extends CI_Controller {
public function processnaivebayes(){
        ........
  }
}

答案 2 :(得分:0)

最重要的是你必须考虑控制器页面的名称应该以大写字母开头。

Datatraining.php
Chisquare.php

按名称保存控制器页面。

控制器类也从大写字母开始。

class Datatraining extends CI_Controller {

public function progress(){

class Chisquare extends CI_Controller {
public function processnaivebayes(){
        ........
  }
}