从另一个控制器代码点火器调用模型的方法


Calling a method of a model from another controller codeigniter

我有两个控制器hrcontrolleradmincontroller

和模型hrmodeladminmodel.

可以从admincontroller访问hrmodel的方法。

在你的admincontroller你只是这样做

$this->load->model('hrmodel'); 
$this->hrmodel->get_data(); 
//replace get_data for a real function on your model

您可以加载所需的所有模型。

这个答案对我不起作用。以下是对我有用的:

$this->load->model('hrcontroller/hrmodel'); $this->hrmodel->myfunction();

使用 CI 执行此操作的正确方法如下:

从控制器执行以下操作:

$this->hrmodel->my_function('in case you wanna pass an argument, place it here.');

在您的模型上执行以下操作:

function my_function('in case youre passing an argument.'){
    //Your functions behavior.
}