在Codeigniter中调用另一个控制器时无法找到指定的类 [英] Unable to locate the specified class while calling another controller in codeigniter
本文介绍了在Codeigniter中调用另一个控制器时无法找到指定的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下用于Qprs控制器的代码
I have following code for controller Qprs
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Qprs extends CI_Controller {
public function xyz()
{
//some code
}
}
用于从另一个控制器调用上方控制器的以下代码
below code used to call above controller from another controller
$this->load->library('../controllers/Qprs');
$this->Qprs->xyz();
但出现错误:
无法找到指定的类Qprs.php
如何解决这种错误?
but getting error:
Unable to locate the specified class Qprs.php
How to solve such error?
推荐答案
在Codeigniter中使用一种非常简单的方法将一个控制器的方法调用到另一个控制器
Very simple way in codeigniter to call a method of one controller to other controller
1. Controller A
class A extends CI_Controller {
public function __construct()
{
parent::__construct();
}
function custom_a()
{
}
}
2. Controller B
class B extends CI_Controller {
public function __construct()
{
parent::__construct();
}
function custom_b()
{
require_once(APPPATH.'controllers/a.php'); //include controller
$aObj = new a(); //create object
$aObj->custom_a(); //call function
}
}
这篇关于在Codeigniter中调用另一个控制器时无法找到指定的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文